Patrick Kelly
Posts: 0
Joined: Wed Nov 20, 2013 6:00 am

How can you get the name of a button into a javascript variable?

This fairly simple. I am making a page that has a button that the user can click that will bring him/her to a website. The website url is that text that is written on the button.

precode
var web = Appery("ButtonName").val();
window.location.href='http://'+web;
/code /pre

This brings me to a page with "a href="http://" rel="nofollow"http:///a" as address, but noting else. I have used an alert to show me what is in the variable and the alert pops up blank. I have tried doing the same thing where the variable gets a value from an input field and that works just fine. So, one would conclude that the code "Appery("ButtonName").val();" actually doesn't get the text on the button.

Is there any way to put the text that is written on a button into a variable?

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

How can you get the name of a button into a javascript variable?

Check the API here: http://docs.appery.io/javascript-api/

.val() is function that works on an input component. To read the value of a button, check jQuery Mobile AP and see which attribute you need to read.

Patrick Kelly
Posts: 0
Joined: Wed Nov 20, 2013 6:00 am

How can you get the name of a button into a javascript variable?

It appears that the text on the button actually isn't an attribute, so I don't think I can retrieve it.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

How can you get the name of a button into a javascript variable?

I think it's another tag inside the button. Once you select the button, select its child (the tag that holds the name).

Return to “Issues”