document.getbyID not working on a specific case ... works on most cases

I have used the document.getElementbyID many times and it normally works for me… However this one has not cooperated with any of my attempts… Could someone take a look and maybe get me the correct path i have tried everything i can think of…if you scroll the file which is php and html you will see a couple of code attempts that did not work.
All I want to do is be able to replace each of the variables with new ones and it is just not working for me as usual… maybe someone can see what I am overlooking…
I have been able to use the old < echo ? = $var; ?> to interract with document but not here.
Thank you:
you will see 3 of these… my testing… not needed…

<?php

$first_name = "Tom"; echo "first_name = $first_name<br>";
$last_name = "Chandler"; echo "last_name = $last_name<br>";
$phone = "757-345-2345"; echo "phone = $phone<br>";
$user_email = "john@bond.com"; echo "user_email = $user_email<br>";
echo 'id="mauticform_input_gf_first_name"  for first_name.';
echo "<br><br>";

?>


    <form autocomplete="false" role="form" method="post" action="https://mydomain.com/form/submit?formId=3" id="mauticform_gf" data-mautic-form="gf" enctype="multipart/form-data">
        <div class="mauticform-error" id="mauticform_gf_error"></div>
        <div class="mauticform-message" id="mauticform_gf_message"></div>
        <div class="mauticform-innerform">

          
          <div class="mauticform-page-wrapper mauticform-page-1" data-mautic-form-page="1">

            <div id="mauticform_gf_first_name" class="mauticform-row mauticform-text mauticform-field-1">
                <input id="mauticform_input_gf_first_name" name="mauticform[first_name]" value="FIRSTNAMEXXX" class="mauticform-input" type="text">
                <span class="mauticform-errormsg" style="display: none;"></span>
            </div>




<document.getElementbyID("mauticform_input_gf_first_name").value=<? echo $first_name; ?>

 


            <div id="mauticform_gf_last_name" class="mauticform-row mauticform-text mauticform-field-2">
                <input id="mauticform_input_gf_last_name" name="mauticform[last_name]" value="LASTNAMEXXX" class="mauticform-input" type="text">
                <span class="mauticform-errormsg" style="display: none;"></span>
            </div>

            <div id="mauticform_gf_phone" class="mauticform-row mauticform-tel mauticform-field-3">
                <input id="mauticform_input_gf_phone" name="mauticform[phone]" value="PHONEXXX" class="mauticform-input" type="tel">
                <span class="mauticform-errormsg" style="display: none;"></span>
            </div>

            <div id="mauticform_gf_email" class="mauticform-row mauticform-email mauticform-field-4">
                <input id="mauticform_input_gf_email" name="mauticform[email]" value="EMAILXXX" class="mauticform-input" type="email">
                <span class="mauticform-errormsg" style="display: none;"></span>
            </div>

            <div id="mauticform_gf_submit" class="mauticform-row mauticform-button-wrapper mauticform-field-5">
                <button type="submit" name="mauticform[submit]" id="mauticform_input_gf_submit" value="" class="mauticform-button btn btn-default">Submit</button>
            </div>
            </div>
        </div>

        <input type="hidden" name="mauticform[formId]" id="mauticform_gf_id" value="3">
        <input type="hidden" name="mauticform[return]" id="mauticform_gf_return" value="">
        <input type="hidden" name="mauticform[formName]" id="mauticform_gf_name" value="gf">

        </form>


</div>
</div>
</table>
</html>


document.getElementbyID("mauticform_input_gf_first_name").value=<? echo $first_name; ?>

document.getElementbyID("mauticform_gf_first_name").value

I suggest you check the capitalisation.

1 Like

Thanks for the response but I cannot find one that is not spelled exactly like that…I may have messed one up in the explanation but i cannot find any active attempts not spelled correctly with case in mind…if you see one please let me know… as i have tried jquery and the whole shooting match… along with javascript… Negative results…

Look again.
smile

1 Like

Let’s try again with more specifics this time.

In your code you have used getElementbyID which is not a valid capitalization. The correct capitalization is getElementById because case matters here.

1 Like

Or better still getElementById :biggrin:

2 Likes

Thanks. Edited and corrected. /me stares in frustration at fingers

3 Likes

Thanks Paul when you told me I was spelling it wrong I should have then looked it up vice using you example…And thanks to you Gandalf as it looks like you solved the final mystery… which could have been solved by me looking it up when Paul told me my capitalizations were wrong
On my way to test right now…but pretty sure I had it right when using jquery… but will know in a minute so thanks to both of you…back soon hoping to mark it done…

RESOLVED!
Thanks Paul and Gandalf… for the help…had i done as Paul said i would have caught it… but I used Pauls own ref… but my bad… never did get it to work… even when correct… so just did it with jqurey and worked fantastic…

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>

<button id="setText">LoadIT</button>

<script>
  $("#setText").click(function(event) {
      $('#mauticform_input_gf_first_name').val(<? echo $first_name; ?>)
      $('#mauticform_input_gf_last_name').val(<? echo $last_name; ?>)
      $('#mauticform_input_gf_phone').val(<? echo $phone; ?>)
      $('#mauticform_input_gf_user_email').val(<? echo $user_email; ?>)
  });
 </script>

Getting the echo for the php varialbes to work wit jquerey took a while but i got the working verions… no quotes around the php conversion is what I needed… but the from filler is great… thanks again…

Glad you’ve got it resolved @shirleymanson. For future reference, looking at the console in the inspect tools can help to debug your script. It won’t tell you the capitalisation is wrong, but it tells you what the problem is.

1 Like

Thanks for that Gandalf every little bit helps… I will try that in the console…

OK i see it now… I am 78 and half blind and had looked at what you wrote several times and this is the first time i saw the one letter wrong … Thanks for your patience with us dummies…

1 Like

Thanks TechnoBear I see the error now…

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.