homepage Welcome to WebmasterWorld Guest from 54.243.12.156
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Code, Content, and Presentation / Flash and Shockwave
Forum Library, Charter, Moderator: open

Flash and Shockwave Forum

    
Dynamically add new inputs in form
Calling a php-script with ajax. Need to add new inputs depending on result
taras78




msg:3351307
 8:35 pm on May 27, 2007 (gmt 0)

Sorry.. got posted in wrong forum.
Feel free to move it to JavaScript and AJAX instead.

Been searching for an answer but not come up with much sofar.

Basically what I'm trying to do is this.

I have a form.
In the form I have a search function inside an input. When a user enter some text it sends the text to a php-script, which updates a div inside the form.

Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>jhweb</title>
<script language="javascript" type="text/javascript">
<!--
//Browser Support Code
function ajaxFunction(){
var ajaxRequest;
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Browser error!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
document.getElementById("newtext").firstChild.nodeValue = ajaxRequest.responseText;
}
}
var doman = document.getElementById('doman').value;
var alla = document.getElementById('alla').value;
var se = document.getElementById('se').value;
var nu = document.getElementById('nu').value;
var eu = document.getElementById('eu').value;
var biz = document.getElementById('biz').value;
var com = document.getElementById('com').value;
var net = document.getElementById('net').value;
var org = document.getElementById('org').value;
var info = document.getElementById('info').value;
var queryString = "?doman=" + doman + "&alla=" + alla + "&se=" + se + "&nu=" + nu + "&eu=" + eu + "&biz=" + biz + "&com=" + com + "&net=" + net + "&org=" + org + "&info=" + info;
ajaxRequest.open("GET", "search.php" + queryString, true);
ajaxRequest.send(null);
}
//-->
</script>
</head>
<body>
<form action="order.php" method="post" name="orderform">
<input type="checkbox" id="alla" name="alla" checked />Alla
<input type="checkbox" id="se" name="se"/>.se
<input type="checkbox" id="nu" name="nu"/>.nu
<input type="checkbox" id="eu" name="eu"/>.eu
<input type="checkbox" id="biz" name="biz"/>.biz <br/>
<input type="checkbox" id="com" name="com"/>.com
<input type="checkbox" id="net" name="net"/>.net
<input type="checkbox" id="org" name="org"/>.org
<input type="checkbox" id="info" name="info"/>.info
Domän: <input type='text' id="doman" name='doman' />
<div id="newtext">&nbsp;</div>
<input type='button' onclick='ajaxFunction()' value='Search' />
</form>
</body>
</html>

What I would like to do is to add some new inputs depending on what result the php-script returns, but I'm a newbie when it comes to adding new elements via JS/Ajax.

At the moment, search.php returns a textstring with true/false for every checkbox in the form.
Is there an easy way to add new inputs?
Or is it easier to update the current checkboxes? Ie disable the checkbox if return=false, enable if true.

Help would be apprecciated :)

 

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Flash and Shockwave
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved