SyntaxError: missing ) after argument list in cart.js - javascript

I'm getting
SyntaxError: missing ) after argument list | in cart.js file
// Purchase button.
add('<button onclick="yaCounter44762137.reachGoal('zakaz'); return true;" class="btn btn-primary cart-purchase-button" type="button"></button>')

If you escape the single quotes like this:
add('<button onclick="yaCounter44762137.reachGoal(\'zakaz\'); return true;" class="btn btn-primary cart-purchase-button" type="button"></button>');
It'll work.

Or you can change the zakaz in double quotes. It would make things a lot easier to do.
add('<button onclick="yaCounter44762137.reachGoal("zakaz"); return true;" class="btn btn-primary cart-purchase-button" type="button"></button>');
Or you can even use one double quote and put everything else in a single quote:
add("<button onclick=yaCounter44762137.reachGoal('zakaz'); return true;' class='btn btn-primary cart-purchase-button' type='button'></button>");

Related

Undefined error when passing row.entity and col.field to function

I need row.entity and col.field to determine if a button needs to be disabled or not, so here's the code for the cellTemplate of my UI-grid
cellTemplate:
'<div *ngIf="{{COL_FIELD}}"> '+
'<div class="ui-grid-cell-contents" > {{COL_FIELD}}' +
'<button uib-tooltip="Modifica" tooltip-placement="auto" ng-disabled="grid.appScope.modificaDisabled(row.entity, col.field)"'+
'rel= "{{row.entity}}" rol="{{col.field}}" '+
'class="btn btn-xs btn-primary stretto" style="float:right;" edit>'+
'<i class="fa fa-pencil fa-fw"></i>'+
'</button>'+
'</div>'+
'</div>'
and here's the function called
var modificaDisabled = function(riga,col){
console.log(riga)
console.log(col)
//disabling logic
}
The problem ( sgrid.appScope.modificaDisabled(row.entity, col.field) ) is that the second parameter passed (in this case col.field) results undefined but if i switch their position (col.field, row.entity ) col.field is actually defined but then row.entity results undefined.
Can anyone help me? I've seen another post talking about the spacing after the comma, but nothing seems to work
I eventually found a "solution" :
ng-disabled="grid.appScope.modificaDisabled([row.entity, col.field])"
by passing the values as an array I get them defined (idk why) and i can finally proceed

How to concat #Url.Action with jquery syntax

I'm using bootstrap datatables to create a column displaying a link button to redirect to another view, the problem is that I'm getting syntax error from jquery and I'm not beign successful fixing it.
Here is the relevant part where I get the syntax error:
return '<button type="button"class="btn btn-default" onclick="location.href='#Url.Action("IncidentesDetalle", "ServiciosController", new { Id = "1" })'"><i class="fa fa-eye"></i></button>'
Any help will be appreciated.
I guess you should change your string to:
return '<button type="button" class="btn btn-default" onclick="location.href=\'#Url.Action("IncidentesDetalle", "ServiciosController", new { Id = "1" })\'"><i class="fa fa-eye"></i></button>'
Because in your original code single quotes just closed after href= and opened before ><i again. So part of the returning string like #Url.... became just invalid code. Hence the error.
Try this, it will work:
string path = "'#Url.Action('IncidentesDetalle', 'ServiciosController', new { Id = '1' })'";
return "<button type='button' class='btn btn-default' onclick='location.href="+path+"'><i class='fa fa-eye'></i></button>";

How to add variable to a href

I want to do something like this
var myname = req.session.name; <------- dynamic
<a href="/upload?name=" + myname class="btn btn-info btn-md">
But this does not work. So how do I properly pass in a dynamic variable to href? <a href="/upload?name=" + req.session.name class="btn btn-info btn-md"> does not work either
Actually there's no way to add a js variable strictly inside DOM. I would suggest you to apply an id attribute to that a element, refer to it and apply given variable as a new href attribute.
var elem = document.getElementById('a'),
myname = 'req.session.name'; //used it as a string, just for test cases
elem.href += myname;
console.log(elem.href);
<a id='a' href="/upload?name=" class="btn btn-info btn-md">Link</a>

React.js - REF undefined

When I test the following code I receive a console error that newText is undefined, am I declaring the val var correctly or am I missing something?
val = ReactDOM.findDOMNode(this.refs[newText]);
renderForm: function() {
return (
<div className="note">
<textarea ref="newText" defaultValue={this.props.children} className="form-control"></textarea>
<button onClick={this.save} className="btn btn-success btn-sm glyphicon glyphicon-floppy-disk"></button>
</div>
)
},
newText here needs to be either a string ("newText") or should use dot notation instead. Using just newText means you're trying to read the value of a variable with that name (which will return undefined).
Change:
this.refs[newText]
To:
this.refs["newText"]
Or:
this.refs.newText
I know it's very late to answer this but I came across the same problem.
I added and update the following sources:
src= "https://unpkg.com/react#15/dist/react.js">
src="https://unpkg.com/react-dom#15/dist/react-dom.js">
It worked for me.
Hope you already found a solution for this.
Cheers!
use this.refs.newText rather than this.refs[newText].

JavaScript get recognize button to click

I am making a Chrome extension and I need this button to be clicked so how can I get the click to be recognized?
<button class="btn btn-lg btn-danger btn-bet" onclick="system.play.bet.red();">RED</button>
I tried var test= document.getElementsByClassName("btn btn-lg btn-black btn-bet");
test.click();
but it fails at the beginning.
Document.getElementsByClassName() returns an array-like object of all child elements which have all of the given class names. Unfortunately, it's not a true JS array. To work with it, you need to "Arrayify" it:
var testElements = document.getElementsByClassName('test');
var testDivs = Array.prototype.filter.call(testElements, function(testElement){
return testElement.nodeName === 'DIV';
});
In your case, this should work:
var test= document.getElementsByClassName("btn btn-lg btn-black btn-bet")[0];
test.click();

Categories