Asp.net post multiple parameters to javascript function - javascript

index.cs
If i post one value below method works.
Page.RegisterClientScriptBlock("Pass", "<script>pass('" + sle_password.Text.Trim() + "');</script>");
If i post multiple value like below it does not work
Page.RegisterClientScriptBlock("Pass", "<script>pass('" + sle_password.Text.Trim() + "','" + sle_username.Text.Trim() + "','" + txt_reseller_ID.Text.Trim() + "')";</script>");
JS Code:
function pass(pass, usrname, resellerId) {
alert(pass,usrnameresellerId);
}
Edited first code
Where i miss in second part code ?

try this
Page.RegisterClientScriptBlock("Pass", "<script>pass('" + sle_password.Text.Trim() + "','" + sle_username.Text.Trim() + "','" + txt_reseller_ID.Text.Trim() + "');</script>");

Related

Replace/Toggle ng-click event once clicked

I am building a web app that allows users to mark which episode of a show they have watched. On load it has a ng-click event called markEpisode(). Once that is clicked, I want the ng-click event to change to unmarkEpisode().
Currently I have it removing the ng-click attribute and then re-adding a new one. But doesn't seem to work.
// Unmark Episode As Watched
$scope.unmarkEpisode = function(episode_number, season_number, id) {
$http.post('/api/show/' + id + '/season/' + season_number + '/episode/' + episode_number + '/unwatch')
.then(response => {
$('.episode-artwork[data-episode-season="' + episode_number + season_number + '"]').removeAttr('ng-click').attr('ng-click', 'markEpisode(' + episode_number + "," + season_number + "," + id + ')');
});
};
This is how I add the episodes in
$('#episodes .row').append($compile('<div class="col-sm-3">' +
'<div data-episode-season="' + response.data.episodes[i].episode_number + response.data.episodes[i].season_number + '" class="episode-artwork" ng-click="markEpisode(' + response.data.episodes[i].episode_number + "," + season_number + "," + id + ')" style="background-image: url(' + imageURL + ')">' +
'</div>' +
'<p class="episode-name">' + response.data.episodes[i].episode_number + '. ' + response.data.episodes[i].name + '</p>' +
'<p class="episode-text">' + response.data.episodes[i].overview + '</p></div>')($scope));
It would be good to have two links or buttons: one for mark, one for unmark.
Each button should have an *ngIf="item.isMarked" or *ngIf="!item.isMarked".
I think that it's not a good idea to mix angular and jquery. If you are working with angular, there is no need to manipulate the dom via jQuery.

Phonegap - inserting variable into database

I'm trying to insert variables values to a data base but it comes out as 'undefined'.
It is all inside device ready. I'm testing 1st with the variable 'absenceDateFrom'.
var absenceType = document.getElementById('absenceType')
var absenceText = document.getElementById('noteNewAbsence')
var absenceDateFrom = document.getElementById('absenceFrom')
var absenceDateTo = document.getElementById('absenceTo')
db.transaction(
function(tx) {
tx.executeSql("INSERT INTO absences (id,type,absenceFrom,absenceTo,note,aproved,picture) VALUES (" + id++
+ ",'"
+ String(absenceType.value)
+ "','"
+ absenceDateFrom.value.toString
+ "','"
+ absenceDateTo.value.toString
+ "','"
+ "random note (this works but if i put absenceText.value it comes out undefined also"
+ "',"
+ "'true'"
+ ","
+ "'image.jpg'"
+ ")");
}, transaction_error);
I also tried with '?' and [absenceDateFrom] in the end, like I saw on another answer and it still comes out undefined:
var absenceType = document.getElementById('absenceType')
var absenceText = document.getElementById('noteNewAbsence')
var absenceDateFrom = document.getElementById('absenceFrom')
var absenceDateTo = document.getElementById('absenceTo')
db.transaction(
function(tx) {
tx.executeSql("INSERT INTO absences (id,type,absenceFrom,absenceTo,note,aproved,picture) VALUES (" + id++
+ ",'"
+ String(absenceType.value)
+ "',"
+ "?"
+ ",'"
+ absenceDateTo.value.toString
+ "','"
+ "random note (this works but if i put absenceText.value it comes out undefined also"
+ "',"
+ "'true'"
+ ","
+ "'image.jpg'"
+ ")", [absenceDateFrom.value] );
}, transaction_error);
output:
http://prntscr.com/44eb31
Following is the assumptions that I have made about datatypes of the variables.
Number id;
String type,absenceFrom,absenceTo,note,aproved,picture;
Also aproved variable seems to be typo error. Should it not be approved
I have modified your tx() call
If there are any errors in the insert call. check the output of the errorInsert call
db.transaction(
function(tx) {
var sqlStmt = "INSERT INTO absences (id,type,absenceFrom,absenceTo,note,aproved,picture) VALUES ("
+ (id++) + ","
+ "'" + String(type) + "',"
+ "'" + String(absenceDateFrom) + "',"
+ "'" + String(absenceDateTo) + "',"
+ "'" + "random note (this works but if i put absenceText.value it comes out undefined also" + "',"
+ "'" + "true" + "',"
+ "'" + "image.jpg" + "',"
+ ")";
console.log("sqlStmt:"+sqlStmt);
tx.executeSql(sqlStmt,successInsert,errorInsert);
function errorInsert (err) {
console.log("ERROR CODE:"+err.code+":Message:"+err.message);
}
function successInsert(tx, result) {
console.log("SuccessInsert():Last inserted ID = " + result.insertId);
console.log("SuccessInsert():rowsAffected: " + result.rowsAffected);
}
}, transaction_error);
First: try to console.log(absenceDateTo) before inserting and be sure that the value is not undefined.
Second: In the line :
absenceDateTo.value.toString
You are passing the function context but you should call the function instead.
absenceDateTo.value.toString()
Try this ;)

onclick event and json data not meshing together

I've got a silly error which I cant seem to fix some how. I'm simply looking to do the following:
onclick="CreatePro('x','y','z')"
I basically want to pass text to the CreatePro function. Now my values of x,y and z are json data. As such here is what I am using for the javascript:
var Provision = "'" + data[i].ProvisionID + "'";
var Title = "'" + data[i].Title + "'";
var Author = "'" + data[i].Author + "'";
var Edition = "'" + data[i].Edition + "'";
var Publisher = "'" + data[i].Publisher+ "'";
var ISBN = "'" + data[i].ISBN + "'";
var UserID = "'" +data[i].UserID + "'";
var Price = "'" + data[i].Price+ "'";
var Condition = "'" +data[i].Condition +"'";
Row = Row + "<td><input type='button' onclick='CreatePro(" + Provision + "," + Title+ "," + Author + "," + Edition + "," + Publisher +"," + ISBN + ","+ UserID + ","+ Price + "," + Condition + ")' value='Create'></td></tr>";
console.log(Row);
Now when I use console.log I get the following:
<td><input type='button' onclick='CreatePro('19','dfjeryj','ertj','0','tj','0000000000000','4','0','0')' value='Create'></td>
But when I inspect the element I have :
<input type="button" onclick="CreatePro(" 19','dfjeryj','ertj','0','tj','0000000000000','4','0','0')'="" value="Create">
The problem is suspect is the " on the above line. But I dont know why this is happening? As from the console log. My quotes seem to match up. So I'm not sure why the browser is mixing them up? Perhaps I've gone wrong somewhere? (Frankly I can;t see the error). Every time I click the create button the event doesn't call my CreatePro function. I'm really not sure what I'm doing wrong or perhaps a better way of doing what I'm doing
You have got your quotes wrong. It should be:
Row = Row + "<td><input type='button' onclick=\"CreatePro('" + Provision + "','" + Title+ "','" + Author + "','" + Edition + "','" + Publisher +"','" + ISBN + "','"+ UserID + "','"+ Price + "','" + Condition + "')\" value='Create'></td></tr>";

Javascript innerHTML not allowing onClick on javascript function

I am not sure why, but the following
href='javascript:"+ openextlink('http://www.ipetfindr.com/shop/product/' + item._id.$id);+"'
seems to run automatically without the user clicking.
document.getElementById("shop-items").innerHTML += "<div class='product " + cssclass + "'><div class='product-images-smaller'><span class='shop-large-image'><img src='" + item.pictures[0] + "'/></span></div><h1>" + item.name + "</h1><div class='prodtext'><b>Status:</b> " + item.status + "<br><b>Price:</b> $" + item.price + "<br><a id='shop_" + item._id.$id + "' href='javascript:"+ openextlink('http://www.ipetfindr.com/shop/product/' + item._id.$id);+"'><h3 id='dshop_" + item._id.$id + "' class='green_button'>Buy Now</h3></a></div></div>";
could anyone please tell me why.
href='javascript:"+ openextlink('http://www.ipetfindr.com/shop/product/'
I see a double quote , is it a typo, change to
href='javascript:'+ openextlink('http://www.ipetfindr.com/shop/product/'

javascript function call for multiple controls

I have a javascript function which I am calling for multiple controls,but it seems to be calling for the first ClientScript.RegisterStartupScript only.
ClientScript.RegisterStartupScript(this.GetType(), "myScript", "textCounter('" + txtCourseDesc.ClientID + "','" + txtRemDesc.ClientID + "', '2000')", true);
ClientScript.RegisterStartupScript(this.GetType(), "myScript", "textCounter('" + txtReqCourseCode.ClientID + "','" + txtRemCode.ClientID + "', '90')", true);
ClientScript.RegisterStartupScript(this.GetType(), "myScript", "textCounter('" + txtPReq.ClientID + "','" + txtPreqRem.ClientID + "', '1000')", true);
Please point out the problem.
You can't use same key for one function with different parameters. Try this:
ClientScript.RegisterStartupScript(this.GetType(), "myScript2000", "textCounter('" + txtCourseDesc.ClientID + "','" + txtRemDesc.ClientID + "', '2000')", true);
ClientScript.RegisterStartupScript(this.GetType(), "myScript90", "textCounter('" + txtReqCourseCode.ClientID + "','" + txtRemCode.ClientID + "', '90')", true);
ClientScript.RegisterStartupScript(this.GetType(), "myScript1000", "textCounter('" + txtPReq.ClientID + "','" + txtPreqRem.ClientID + "', '1000')", true);

Categories