...

View Full Version : Javascripting



dolton
08-31-2008, 01:53 PM
Im trying to use button on the main page. When that button is cliked, it calls a function to display the other buttons. Im displaying the buttons using document.write function. But the other buttons go onto the different.
How to get them on the same page??
The code i use to do this is:
<html>
<head>
<script type="text/javascript" src="loadxmldoc.js">

</script>
</head>
<script type="text/javascript">

</script>
<form id="form1">
<button id="button1"onclick='call()'>Get CD info</button>
</form>


<script type="text/javascript">
function call()
{
document.write("<input type='button' onclick='go1()' value='Title list'>");
document.write("<input type='button' onclick='go2()' value='Artist List'>");
document.write("<input type='button' onclick='go3()' value='Country List'>");
document.write("<input type='button' onclick='go4()' value='Company List'>");
document.write("<input type='button' onclick='go5()' value='Price List'>");
document.write("<input type='button' onclick='go6()' value='Year List'>");
}
</script>
</body>
</html>

BarrMan
08-31-2008, 02:19 PM
Don't use document.write for that.
Use either DOM or innerHTML.

Philip M
08-31-2008, 02:32 PM
Here you are:-


<form id="form1">
<button id="button1"onclick='call()'>Get CD info</button>
</form>

<div id = "div1" style="visibility:hidden">
<input type='button' onclick='go1()' value='Title list'>
<input type='button' onclick='go2()' value='Artist List'>
<input type='button' onclick='go3()' value='Country List'>
<input type='button' onclick='go4()' value='Company List'>
<input type='button' onclick='go5()' value='Price List'>
<input type='button' onclick='go6()' value='Year List'
</div>

<script type = "text/javascript">
function call() {
document.getElementById("div1").style.visibility="visible";
}
</script>


Haikus are easy
But sometimes they don't make sense.
Refrigerator.

dolton
08-31-2008, 03:01 PM
That was so knowledgeable! Thanks.
Also if u refer to that example in reply, if i click on 'title list" button it calls the function go1().
How do i get the output of that also on the same page?

BarrMan
08-31-2008, 03:49 PM
That's what I meant.

<form id="form1">
<button id="button1"onclick='call()'>Get CD info</button>
</form>

<div id = "div1" style="visibility:hidden">
<input type='button' onclick='go1()' value='Title list'>
<input type='button' onclick='go2()' value='Artist List'>
<input type='button' onclick='go3()' value='Country List'>
<input type='button' onclick='go4()' value='Company List'>
<input type='button' onclick='go5()' value='Price List'>
<input type='button' onclick='go6()' value='Year List'
</div>
<div id="go1">
</div>

<script type = "text/javascript">
function call() {
document.getElementById("div1").style.visibility="visible";
}
function go1()
{
document.getElementById("go1").innerHTML = "OutPut"
}
</script>

dolton
08-31-2008, 05:10 PM
function go1()
{
document.getElementById("go1").innerHTML = "OutPut"
}
------instead of the "output", can we call another function in there.
like the following:
function go1()
{
document.getElementById("go1").innerHTML= list()
}
Function list()
{
document.write("hello")
}
but this goes to another page again...... javascripting if fun!

Philip M
08-31-2008, 06:17 PM
You cannot have a function with the same name (go1) as a <div> or other element.

Once more, avoid document.write. Use DOM or innerHTML.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum