Jump to content

javascript function problem with onclick="check()"


helloise

Recommended Posts

i have some html code:<td width='200px'><input type="checkbox" name="graphic[]" value="<?php echo $product_row->getId();?>" onclick="check()"/></td>and then the java script code for the function check:<script type="text/javascript"> function check() { var graphics = document.getElementsByName("graphic[]"); for(i=0;i<graphics.length;i++) { if(graphics.checked) { var gchecked = true; if(document.getElementById('submit').style.display=='none') { document.getElementById('submit').style.display='block'; } } } var text = document.getElementsByName("text[]"); for(i=0;i<text.length;i++) { if(text.checked) { var tchecked = true; if(document.getElementById('submit').style.display=='none') { document.getElementById('submit').style.display='block'; } } } } </script>how do i pass the booleans back to the onclick so i can check the values further in my code???something like: <td width='200px'><input type="checkbox" name="graphic[]" value="<?php echo $product_row->getId();?>" onclick="check(var isgchecked,var istchecked)"/></td>then further in my code i can for instance say:<?php if (istchecked = true){ //do something}if (isgchecked=true){ //do something}can somebody help please...this is my first time working with javascriptthanks

Link to comment
Share on other sites

you can't mix javascript and PHP like that. Once the code has been sent to the browser, PHP has finished executing; unless you were planning on integrating some sort of AJAX call or form handling into the page. To return a value from a function though, you can use the return keyword.Maybe if you explained the nature of the code and what you want to happen and in what order, we could help you out. From the looks of it you are trying to show and hide things on the page, which is easy enough to do with Javascript. What are your intentions regarding the PHP integration after the fact?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...