0

I am trying to call method with parameter in java script onclick='addAlertDlg.show();preparePOIAlertToCreate(name)'

function preparePOIAlertToCreate(name){
    alert(name);
    document.getElementById('bottomForm:refId').value = name;       
}

But alert(name); showing nothing.

any thing wrong in my code?

4
  • 4
    What is name and where is it defined? Commented Sep 25, 2013 at 7:18
  • have you assigned anything to name variable ? Commented Sep 25, 2013 at 7:20
  • Does "showing nothing" mean that an alert pops up but is blank, as might happen if your name variable is set to an empty string, or is not declared at all in which case it'll be the built-in window.name property that is quite likely an empty string? Or do you mean that nothing happens at all (no alert)? Commented Sep 25, 2013 at 7:53
  • yeh i have assigned value to 'name' @ LightStyle, @ SKV Commented Sep 25, 2013 at 8:07

3 Answers 3

1

Don't use inline event handling. Use the following approach:

var element = document.querySelector(".your-link-class");
element.addEventListener("click", function() {
    addAlertDlg.show();
    preparePOIAlertToCreate(name);
});
function preparePOIAlertToCreate(name){
    alert(name);
    document.getElementById('bottomForm:refId').value = name;       
}

If you do this you will find out that name is probably not defined. Also you will get a good feedback in the console.

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

Comments

0

try calling function as

onclick='addAlertDlg.show();preparePOIAlertToCreate("name")'

if you dont put 'name' in quotation marks, js will search a variable named 'name', so it cant find anything and cant show anything.

Comments

0

The way you use the function is right, but I guess you didn't set the name any value.

Comments

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.