0

I want the value of a variable named button_name to be set on a button event listener and send it in URL as REQUEST parameter. But what is happening the host variable is set on page load and does not take the value of updated variable. Any idea how to set the value of the variable dynamically and send it as REQUEST parameter?

var button_name;

 $.Settings(
 {  
    host : 'http://my_server_Address/abc.php?filename='+button_name,
 })

 function name_setter(name)
{
button_name=name;
}

<input type='button' onclick="name_setter('click_me')" value='click_me'/>

Please suggest if you think it can be done in some other way.

1
  • What the heck is $.Settings? Commented Feb 7, 2013 at 18:31

1 Answer 1

1

When you are calling $.Settings, the host string is being evaluated right then and there. At that point button_name is undefined.

Changing the button_name variable later on won't have any affect, since the string was already evaluated.

Check to see if the host parameter can accept a function instead of just a string.

Sign up to request clarification or add additional context in comments.

2 Comments

Hazmat thanks,Yes you are right same is happening but i want to set the button_name on listener and then it should go to php file.
@Ali: You're gonna have to move the $.Settings call inside the click handler, so that the string is evaluated at the right time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.