Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-10-2012, 04:57 PM   PM User | #16
jdpaul
New Coder

 
Join Date: Feb 2012
Location: East Tennessee
Posts: 56
Thanks: 7
Thanked 0 Times in 0 Posts
jdpaul is an unknown quantity at this point
I'll be back

gotta go to work, I'll try again later *sighs of frustration*
__________________
Janice Paul
jdpaul is offline   Reply With Quote
Old 03-10-2012, 05:02 PM   PM User | #17
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,100
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
These examples ought to point you the right way:-

Code:
<form>
The Date <input type = "text" id = "date"><br>
Quantity 1<input type = "text" id = "qty1"><br>
</form>

<script type = "text/javascript">

window.onload = initForm;

function todayTxt() {
var Today = new Date();
return Today.getMonth()+1+"-"+Today.getDate()+"-"+Today.getFullYear();
}

function initForm() {
document.getElementById("date").value = todayTxt();  // address element by id
document.getElementById("qty1").focus();
}
</script>
Or

Code:
<form>
The Date <input type = "text" name= "date" id = "date"><br>
Quantity 1<input type = "text" name = "qty1" id = "qty1"><br>
</form>

<script type = "text/javascript">

window.onload = initForm;

function todayTxt() {
var Today = new Date();
return Today.getMonth()+1+"-"+Today.getDate()+"-"+Today.getFullYear();
}

function initForm() {
document.forms[0].date.value = todayTxt();   // address element by name
document.forms[0].qty1.focus();
}
</script>
Or, most correctly, assign the id "myform" to the form and then

Code:
function initForm() {
document.getElementById('myform').date.value = todayTxt(); // address form by id, form element by name
document.getElementById("myform").qty1.focus();
}

var document orders // the name of a variable may not contain a space.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 03-10-2012 at 05:39 PM..
Philip M is offline   Reply With Quote
Old 03-11-2012, 08:01 PM   PM User | #18
jdpaul
New Coder

 
Join Date: Feb 2012
Location: East Tennessee
Posts: 56
Thanks: 7
Thanked 0 Times in 0 Posts
jdpaul is an unknown quantity at this point
Is this not what you are talking about?
Code:
<body>
<form id="orders" method="post" action="done.htm">

   <div id="links">
      <a href="#" class="newgroup">Home Page</a>
By using the second suggestion of yours I got the current date and the focus to appear. I'll be back later to put what little I have online where we can both see my mess. I don't understand why using the different syntax worked. still, but I DO NOT GIVE UP!
__________________
Janice Paul

Last edited by jdpaul; 03-11-2012 at 08:06 PM.. Reason: progress w/ the problem I am working on
jdpaul is offline   Reply With Quote
Old 03-11-2012, 11:44 PM   PM User | #19
jdpaul
New Coder

 
Join Date: Feb 2012
Location: East Tennessee
Posts: 56
Thanks: 7
Thanked 0 Times in 0 Posts
jdpaul is an unknown quantity at this point
Smile Online and making slow progress...

I have gotten the focus and select to work I think. When you first see the page loaded the first field for a quantity of GoMap 1.0 has the edge lit up and the blue on the number in Google Chrome only, I guess I need to learn more CSS to get the golden border to show in Firefox and IE(and I probly need to save that for my time & get the rest of this dang form to work right first. Before I tackle the next piece of code to be added would you please look at this: My Web Form After dinner I guess I will tackle the productCosts function. *sigh* This stuff is a lot harder than HTML and CSS!
Quote:
“Dream as if you'll live forever, live as if you'll die today.”
Albert Einstein
I love some of the things he said.
__________________
Janice Paul
jdpaul is offline   Reply With Quote
Old 03-14-2012, 12:43 AM   PM User | #20
jdpaul
New Coder

 
Join Date: Feb 2012
Location: East Tennessee
Posts: 56
Thanks: 7
Thanked 0 Times in 0 Posts
jdpaul is an unknown quantity at this point
Question Someone help me figure out where this code is buggy please!

I have redone this javascript three times now, but it still only gives me the focus and the select ... it is supposed to add the cost amount when you put in a number in the quantity and hit tab ... Firebug tells me nothing. Any suggestions would be greatly appreciated. Janice's Form
__________________
Janice Paul
jdpaul is offline   Reply With Quote
Old 03-18-2012, 05:04 AM   PM User | #21
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,054 Times in 4,023 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
As Philip kept telling you, you can't use the code
Code:
document.orders
unless you have a <form> with that name.

You do *NOT* have such. You have a <form> with that ID!

You could fix this part by changing to
Code:
<form name="orders" method="post" action="done.htm">
But form names are considered obsolescent, anyway. So better to leave the <form> tag as you have it and simply change to using
Code:
document.getElementById("orders")
I would suggest this:
Code:
function initForm() {
   var form = document.getElementById("orders");
   form.date.value = todayTxt();
   form.qty1.focus();
   form.qty1.select();
}
************

You do have another problem, though. You can't use method="post" if the action= of a <form> is another HTML page. You can only use method="post" when the target action is a server-side page (e.g., a PHP or ASP or JSP or CGI page).

Now, if your <form> will never actually be submitted to the action page (which may well be the case for this page you are working on), then the method won't matter. But as a matter of good practice, if you are going to specify action="done.htm" then you should also specify method="get"
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote
Users who have thanked Old Pedant for this post:
jdpaul (03-19-2012)
Old 03-18-2012, 10:03 AM   PM User | #22
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,100
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
The links to your form return 404 errors. Please do try to make it a little easier for us to help you!
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 03-18-2012, 10:41 PM   PM User | #23
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,054 Times in 4,023 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
The correct URL is this:
http://web-students.pstcc.edu/web230...les/order.html

Looks to me like it is all working correctly, now.

No?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote
Old 03-18-2012, 10:43 PM   PM User | #24
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,054 Times in 4,023 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
But, as I told you, your SUBMIT button doesn't work because of the method="post"

WHen you get to the "done.html" page, you get a 405 error, which says this:
Quote:
HTTP Error 405 - The HTTP verb used to access this page is not allowed.
The "verb" in question is "post" (instead of "get"). HTML is not allowed to process "post" requests.

Okay?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote
Old 03-18-2012, 10:46 PM   PM User | #25
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,054 Times in 4,023 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Whoops...I take it back: Your form validation isn't complete. You allow an order to be submitted even if no items are ordered.

Easy fix: If the sales tax is zero, then no items were ordered.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote
Old 03-19-2012, 02:32 PM   PM User | #26
jdpaul
New Coder

 
Join Date: Feb 2012
Location: East Tennessee
Posts: 56
Thanks: 7
Thanked 0 Times in 0 Posts
jdpaul is an unknown quantity at this point
Smile just that one little nudge did it!!!


All I needed was a nudge in the right direction. Awesome dude!!! I did not write the html form the way it was .. but when I changed the wording like you suggested it works fine now. I pray when I go home to put it online live it will continue to behave.
Thanks so much,
__________________
Janice Paul
jdpaul is offline   Reply With Quote
Old 03-19-2012, 10:33 PM   PM User | #27
jdpaul
New Coder

 
Join Date: Feb 2012
Location: East Tennessee
Posts: 56
Thanks: 7
Thanked 0 Times in 0 Posts
jdpaul is an unknown quantity at this point
form done!

Phillip, I apologize for not seeing your posts! I was under the weather this last weekend. I did not write the form and the way they did the method and the submission part. I really am not sure how it ended up this way. Thanks to your guidance and Old Pedant's I have successfully gotten the form to do what was asked of me. THANK GOD! I thought these people were supposed to know something when they published a book! Hmm, I am not amused with their mess-ups. But, I don't give in and I WILL learn JavaScript one way or the other. Thanks so much for your patience as I struggle with a crumby book and no help outside here.
__________________
Janice Paul
jdpaul is offline   Reply With Quote
Reply

Bookmarks

Tags
form validation, forms, javascript

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:53 AM.


Advertisement
Log in to turn off these ads.