homepage Welcome to WebmasterWorld Guest from 54.234.2.88
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PLEASE HELP in PHP and Javascript
PLEASE HELP in PHP and Javascript
sweetguyzzz




msg:4075356
 8:37 am on Feb 6, 2010 (gmt 0)

Hello Senior Webmasters

I have created a form in PHP in which using a javascript to add some extra fields but when user submits a form or any error found then form will be returned with errors but problem is here that the fields added from the javascript are not returning their previous values like in a field of email address a user inputs: example@xyzcom
and by mistake he or she did not place a dot(.) between "xyz" and "com", so there error will be occured and PHP form will be returned again but with some errors, so with error a value user entered in that javascript created field must be returned but its not returning. Any body can please solve my problem. Please send some type of script as example so this will clearly solving my problem.



MY PHP PAGE CODE IS:
================================================================================================
<html>
<head>
<script type='text/javascript'>
function AddFields() {
var MainDiv = document.getElementById('MoreFunnyImages');//for getting the element(div) from where to start putting more fields
var AddFields = document.getElementById('NoofFunnyImages').value;//for getting number of fields to be added
var PreviousNoOfFields = document.getElementById('FunnyImagesCount');//this is to get the value of field which have saved the number which is given before
var NewDivIdName = 'divFunnyImage';//to get the id of div which have to be removed or been added



for (j=1;j<=PreviousNoOfFields.value;j++) {//loop is for removing previous given DIVS
var OldDiv = document.getElementById(NewDivIdName+j);//getting the name of previous DIVS by help of there ids
MainDiv.removeChild(OldDiv);//removing that DIV from the parent DIV
}
PreviousNoOfFields.value = AddFields;//Now we are assigning new value to the previous value variable so next time this amount of divs will be removed


if (AddFields && AddFields > 0) {
for (i=1;i<=AddFields;i++) {//for loop continue till the given value becomes equal
var NewDiv = document.createElement('div');//gving that what element to be created, we give DIV
NewDiv.setAttribute('id',NewDivIdName+i);//setting id attribute for the div
NewDiv.innerHTML = "Alt Tag "+i+":<input type='text' name='alt"+i+"' value='' class='field' /><br /><br />";
MainDiv.appendChild(NewDiv);//from where to print these div we give a variable.appendChild function with attribute of newdivname
}//loop bracket closes here
}//if condition closes here
}//function closes here
</script>
</head>

<body>

<?php
extract($_GET);
extract($_POST);

if ($action == "submit") {
$show_fields = "AddFields();";
}

echo "<form name='AddFunnyImages' enctype='multipart/form-data' method='post' action='?action=submit'>

Number of Images:<input id='NoofFunnyImages' type='text' name='imagesfield' value='$imagesfield' /><input id='FunnyImagesCount' type='hidden' name='countfield' value='0' />
<input type='button' value='Submit' onclick='AddFields()' />
<div id='MoreFunnyImages'></div><!--All of The Images Browse Button Will Display in This DIV-->
<input type='submit' name='submit' value='Go..' />
</form>
<script type='text/javascript'>$show_fields</script>
";
?>

</body>
</html>
================================================================================================



Please answer fast it is important.
I will be very much thankful to helpers.
And thanks in advance to helpers

[edited by: eelixduppy at 5:10 pm (utc) on Feb 6, 2010]
[edit reason] removed URL [/edit]

 

sweetguyzzz




msg:4075622
 1:57 am on Feb 7, 2010 (gmt 0)

Hey why do you remove the URL, it is sample for the given code then a user can understand my problem clearly.. Can anyone please answer my question ?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved