Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript New and lost. How does this work?

Pbjman

Coder
Code:
<form action="/initial.html" method="post" id="signin">
<input type="text" id="name" name="name" placeholder="Enter your fullname" />
<input type="text" id="handle" name="handle" placeholder="Enter your Handle" />
<input type="hidden" id="rank" name="rank" placeholder="CommanderI" />
<input type="hidden" id="money" name="money" placeholder="25,000EC" />
<input type="submit">
<script type="text/javascript">
const form  = document.getElementById('signin');

form.addEventListener('submit', (event) => {
    // handle the form data
    const name = form.elements['name'];
    const handle = form.elements['handle'];
    const rank = form.elements['rank'];
    const money = form.elements['money'];
    // getting the element's value
let name = name.value;
let handle = handle.value;
let rank = rank.value;
let money = money.value;
});
</script>

I have this code, which is in a child iframe, I am not even sure if it is correct? Some of it is from a tutorial I found on the www. Anyway what I want to do is take these variables and post them to index.html and make them into a session anyone care to comment are welcome.
 
What output would you have expected and where ? Did you look at the debugger Console ?
Is the code in the event listener being executed at all ? Put an alert() statement in there to be sure. Not that this listener is doing anything except for setting some local variables which are not being used anywhere.
And does it actually load initial.html ? What does that look like ?
 
Last edited by a moderator:
initial.html looks like it should I was expecting to see the info displayed on the initial.html page for testing once the form was submitted I will see the debug console and see what I come up with.
 
Code:
<script type="text/javascript">
const form  = document.getElementById('signin');
let myUsername = document.getElementById('name');
let myHandle = document.getElementById('handle');
let myRank = document.getElementById('rank');
let myMoney = document.getElementById('money');
console.log(myHandle);
alert("This was posted");
</script>

I changed it up some I have tried this and nothing still what am I doing wrong point me to a tutorial that works please!!
 
You could consider posting complete code instead of just snippets.
And give a meaningful description of your issue instead of useless statements like "I changed it up some" and "nothing still".
 
Code:
<form action="initial.html" method="post" id="signin">
<input type="text" id="name" name="name" placeholder="Enter your fullname" />
<input type="text" id="handle" name="handle" placeholder="Enter your Handle" />
<input type="hidden" id="rank" name="rank" placeholder="CommanderI" />
<input type="hidden" id="money" name="money" placeholder="25,000EC" />
<input type="submit">
<script type="text/javascript">
const form  = document.getElementById('signin');
let myName = document.getElementById('name');
let myHandle = document.getElementById('handle');
let myRank = document.getElementById('rank');
let myMoney = document.getElementById('money');
console.log(myName);
alert("This was posted");
</script>
Ok sorry for the lack of information I am trying to make a session based game. I have a side navigation with links that works fine the other 2 div elements are iFrames one, which is this one, is where most of the information is displayed. The other iframe is just for pictures. What I want to do is take the form data and write it to session variables that will be able to pass information back and forth between or with the intial page or pages. I hope that clarifies some more. I also changed it again and took the forward slash out and the alert popped up on initial page load I closed it and entered the form data again but the result was just the alert.
 
That is not complete code. Please post the full html, as well as the initial.html, so that someone can see what is happening.
So it seems that at least you are now getting to the submit event handler, which is progress. But as I wrote, that handler is not doing anything useful so what is the point of having it ? Or was it just for the purpose of checking ?
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom