[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

javascript not working

Posted on 2011-09-08
4
Medium Priority
?
210 Views
Last Modified: 2012-05-12
I write the simple form display(hide and show) use in javascript..this form output not display in google chrome..IE and firefox working correctly,. but chrome not display the output..what is the mistake in my program..plz send me comments..here i paste in my html and js file..
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Dynamic Order Form</title>
<script language="JavaScript" type="text/javascript"
src="dform.js">
</script>
</head>
<body>
<h1>Order Form</h1>
<hr>
<form name="form1">
  <b>Bill to:</b><br>
  <b>Name:</b>
  <input type="text" name="customer" size="20" id="txt">
  <br>
  <b>Address 1:</b>
  <input type="text" name="addr1" size="20">
  <br>
  <b>Address 2:</b>
  <input type="text" name="addr2" size="20">
  <br>
  <b>City:</b>
  <input type="text" name="city" size="15">
  <b>State:</b>
  <input type="text" name="state" size="4">
  <b>Zip:</b>
  <input type="text" name="zip" size="9">
  <hr>
  <b>Ship to:</b><br>
  <input type="radio" name="shipopt" value="same" checked onClick="Show(0);">
  <b>Same Address</b>
  <input type="radio" name="shipopt" value="other" onClick="Show(1);">
  <b>Other Address</b>
  <div ID="shipto" style="display: none;"> <br>
    <b>Name:</b>
    <input type="text" name="shipname" size="20">
    <br>
    <b>Address 1:</b>
    <input type="text" name="shipaddr1" size="20">
    <br>
    <b>Address 2:</b>
    <input type="text" name="shipaddr2" size="20">
    <br>
    <b>City:</b>
    <input type="text" name="shipcity" size="15">
    <b>State:</b>
    <input type="text" name="shipstate" size="4">
    <b>Zip:</b>
    <input type="text" name="shipzip" size="9">
  </div>
  <hr>
  <a href="#" onClick="toggle_visibility('foo');">Click here to toggle visibility of element #foo</a>
  <div id="foo">This is foo</div>
  <div ID="items"> <b>Qty:</b>
    <input type="text" name="qty" size="3">
    <b>Item:</b>
    <input type="text" name="item" size="45">
    <br>
    <input type="button" value="Add an Item" onClick="AddItem();" ID="add">
  </div>
  <hr>
  <input type="submit" value="Continue..." onClick="display();">
</form>
</body>
</html>
__________________________________________________________
// global variable
var items=1;
function AddItem() {
if (!document.getElementById) return;
// Add an item to the form
div=document.getElementById("items");
button=document.getElementById("add");
items++;
newitem="<b>Qty: </b>";
newitem+="<input type=\"text\" name=\"qty" + items;
newitem+="\" size=\"3\"> ";
newitem+="<b>Item: </b>";
newitem+="<input type=\"text\" name=\"item" + items;
newitem+="\" size=\"45\"><br>";
newnode=document.createElement("span");
newnode.innerHTML=newitem;
div.insertBefore(newnode,button);
}
function display()
{
	var dis;
	dis=document.form1.customer.value+ "</br>";
	dis+=document.form1.addr1.value+ "</br>";
	dis+=document.form1.addr2.value+ "</br>";
	dis+=document.form1.city.value+ "</br>";
	dis+=document.form1.state.value+ "</br>";
	dis+=document.form1.zip.value+ "</br>";
	obj=document.getElementById("shipto");
	if(obj.style.display=="block") 
	{
	dis+=document.form1.shipname.value+ "</br>";
	dis+=document.form1.shipaddr1.value+ "</br>";
	dis+=document.form1.shipaddr2.value+ "</br>";
	dis+=document.form1.shipcity.value+ "</br>";
	dis+=document.form1.shipstate.value+ "</br>";
	dis+=document.form1.shipzip.value+ "</br>";
	document.write(dis);
	document.close();
	}
	else
	{
	document.write(dis);
	document.close();
	}	

}
function toggle_visibility(id) {
       var e = document.getElementById(id);
      if(e.style.display == 'block')
         e.style.display = 'none';
      else
       e.style.display = 'block';
}
function Show(a) {
//if (!document.getElementById) return;  //hide i
//Hide or show ship-to address
obj=document.getElementById("shipto");
if (a) obj.style.display="block";
else obj.style.display="none";
}

Open in new window

0
Comment
Question by:codeoxygen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 36508106
change:
<script language="JavaScript" type="text/javascript"
src="dform.js">
</script>

To:
<script type="text/javascript" src="dform.js"></script>

===========
change:
<a href="#" onClick="toggle_visibility('foo');">

to:
<a href="#" onclick="return toggle_visibility('foo');">

===========
function toggle_visibility(id) {...}

needs return false; at the end

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Dynamic Order Form</title>
<script type="text/javascript" >
// global variable
var items=1;
function AddItem() {
if (!document.getElementById) return;
// Add an item to the form
div=document.getElementById("items");
button=document.getElementById("add");
items++;
newitem="<b>Qty: </b>";
newitem+="<input type=\"text\" name=\"qty" + items;
newitem+="\" size=\"3\"> ";
newitem+="<b>Item: </b>";
newitem+="<input type=\"text\" name=\"item" + items;
newitem+="\" size=\"45\"><br>";
newnode=document.createElement("span");
newnode.innerHTML=newitem;
div.insertBefore(newnode,button);
}
function display()
{
	var dis;
	dis=document.form1.customer.value+ "</br>";
	dis+=document.form1.addr1.value+ "</br>";
	dis+=document.form1.addr2.value+ "</br>";
	dis+=document.form1.city.value+ "</br>";
	dis+=document.form1.state.value+ "</br>";
	dis+=document.form1.zip.value+ "</br>";
	obj=document.getElementById("shipto");
	if(obj.style.display=="block") 
	{
	dis+=document.form1.shipname.value+ "</br>";
	dis+=document.form1.shipaddr1.value+ "</br>";
	dis+=document.form1.shipaddr2.value+ "</br>";
	dis+=document.form1.shipcity.value+ "</br>";
	dis+=document.form1.shipstate.value+ "</br>";
	dis+=document.form1.shipzip.value+ "</br>";
	document.write(dis);
	document.close();
	}
	else
	{
	document.write(dis);
	document.close();
	}	

}
function toggle_visibility(id) {
       var e = document.getElementById(id);
      if(e.style.display == 'block')
         e.style.display = 'none';
      else
       e.style.display = 'block';
return false;
}
function Show(a) {
//if (!document.getElementById) return;  //hide i
//Hide or show ship-to address
obj=document.getElementById("shipto");
if (a) obj.style.display="block";
else obj.style.display="none";
}
</script>
</head>
<body>
<h1>Order Form</h1>
<hr>
<form name="form1">
  <b>Bill to:</b><br>
  <b>Name:</b>
  <input type="text" name="customer" size="20" id="txt">
  <br>
  <b>Address 1:</b>
  <input type="text" name="addr1" size="20">
  <br>
  <b>Address 2:</b>
  <input type="text" name="addr2" size="20">
  <br>
  <b>City:</b>
  <input type="text" name="city" size="15">
  <b>State:</b>
  <input type="text" name="state" size="4">
  <b>Zip:</b>
  <input type="text" name="zip" size="9">
  <hr>
  <b>Ship to:</b><br>
  <input type="radio" name="shipopt" value="same" checked onClick="Show(0);">
  <b>Same Address</b>
  <input type="radio" name="shipopt" value="other" onClick="Show(1);">
  <b>Other Address</b>
  <div ID="shipto" style="display: none;"> <br>
    <b>Name:</b>
    <input type="text" name="shipname" size="20">
    <br>
    <b>Address 1:</b>
    <input type="text" name="shipaddr1" size="20">
    <br>
    <b>Address 2:</b>
    <input type="text" name="shipaddr2" size="20">
    <br>
    <b>City:</b>
    <input type="text" name="shipcity" size="15">
    <b>State:</b>
    <input type="text" name="shipstate" size="4">
    <b>Zip:</b>
    <input type="text" name="shipzip" size="9">
  </div>
  <hr>
  <a href="#" onclick="return toggle_visibility('foo');">Click here to toggle visibility of element #foo</a>
  <div id="foo">This is foo</div>
  <div ID="items"> <b>Qty:</b>
    <input type="text" name="qty" size="3">
    <b>Item:</b>
    <input type="text" name="item" size="45">
    <br>
    <input type="button" value="Add an Item" onClick="AddItem();" ID="add">
  </div>
  <hr>
  <input type="submit" value="Continue..." onClick="display();">
</form>
</body>
</html>

Open in new window

0
 

Author Comment

by:codeoxygen
ID: 36508237

Now function toggle_visibility(id) {...} working good,. but display() function not working in google chrome and data not print in another page(document.write(dis)) in google chrome...
0
 
LVL 82

Accepted Solution

by:
hielo earned 1000 total points
ID: 36511815
Try:
 <input type="button" value="Continue..." onClick="display();">
0
 
LVL 9

Expert Comment

by:user_n
ID: 36512583
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
In this Micro Tutorial users will learn how to embed custom fonts into websites using @font-face in CSS Select a font: Ensure the EULA allows you to use @font-face: Download the font: Get the browser-compatible files you need: Edit your CSS       - Name …
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question