Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts

    onClick function broken

    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
    PHP Code:
           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.
    PHP Code:
        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!

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,793
    Thanks
    19
    Thanked 156 Times in 147 Posts
    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:

    Code:
    document.form.input2.value='Jon's Gold';
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #3
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks!!!

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

  • #4
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,793
    Thanks
    19
    Thanked 156 Times in 147 Posts
    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?
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #5
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Here is the html code
    PHP 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
    PHP 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.

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    It would work but then why are you even passing anything to the function if they are just overwritten with global variables from php?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #7
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    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);?>

  • #8
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_
    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?

  • #9
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Beagle
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •