...

View Full Version : onClick function broken



lansing
06-02-2006, 06:02 PM
I have this code below that when the user clicks the button it automatically fills 2 input boxes. Right now as the code is below neither input1 or input2 will get filled. If I just delete line 4 then input1 will get filled.

This is the code in the page
function addacct(eg)
{
document.form.input1.value='<?=$abc ?>';
document.form.input2.value='<?=$ab ?>';
}


This is the source code for the page after the page loads & as you can tell the data is being displayed in the function, but the function isn't inserting into the input boxes.
function addacct(eg)
{
document.form.input1.value='56214202';
document.form.input2.value='Jon's Gold';
}


I have tried using this <? echo "$ab" ?> instead of <?=$ab ?>, but it didn't fix it & make it work.

Thanks!

chump2877
06-02-2006, 06:53 PM
you need to show us the HTML form code and js function call, or else its impossible to know for sure what the problem is...

that being said, you do have a problem with single quotes for this line:


document.form.input2.value='Jon's Gold';

lansing
06-02-2006, 08:28 PM
Thanks!!!

I used double quotes & it fixed my problem. Will this function the way I have it coded using onClick work in all browsers?

chump2877
06-02-2006, 08:35 PM
onClick works cross-browser, yes...

will all of your js code work cross-browser? that depends, because you didn;t give us all of the code here...;) ....so I couldn;t tell you for sure...

Have you tested all of your code in multiple browsers?

lansing
06-02-2006, 10:17 PM
Here is the html code
<input type="radio" name="input1" value="Option_1" onClick="addeg('eg')"/>
<input type="radio" name="input2" value="Option_2" onClick="addeb('eb')"/>


Here is the JS code
<script language="javascript">
<!--
function addeg(eg)
{
document.form.input1.value="<?=$abc ?>";
document.form.input2.value="<?=$ab ?>";
}
function addeb(eb)
{
document.form.input1.value="<?=$inD9?>";
document.form.input2.value="<?=$inD8 ?>";
}
// -->
</script>
Let me know if this would work in all/most browsers. I haven't tried it all browsers. Just a couple. I wish there was a program that would let me view a page in multiple browsers.

_Aerospace_Eng_
06-02-2006, 10:20 PM
It would work but then why are you even passing anything to the function if they are just overwritten with global variables from php?

Beagle
06-02-2006, 10:27 PM
Your code is very barebones, I'm sure it would work.

As for the quotes problem, it will break as soon as the PHP is outputting something with double quotes.

You need to do:

<?= str_replace('"', '\\"', $abc);?>

lansing
06-02-2006, 11:16 PM
It would work but then why are you even passing anything to the function if they are just overwritten with global variables from php?I don't understand your question: why are you passing anything to the function if they are just overwritten with global variables from php?

lansing
06-02-2006, 11:23 PM
Your code is very barebones, I'm sure it would work.

As for the quotes problem, it will break as soon as the PHP is outputting something with double quotes.

You need to do:

<?= str_replace('"', '\\"', $abc);?>Thanks...I was woried about that.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum