Jump to content

change javascript variable based on php...


Dragen

Recommended Posts

Hi,

not sure if this should be in javascript or php...

I've got a script which allows someone to insert an extra text input into a form:

var arrInput = new Array(0);
var arrInputValue = new Array(0);

function addInput() {
  if (arrInput.length < 1) {
  arrInput.push(arrInput.length);
  arrInputValue.push("");
  }
  display();
}

function display() {
  document.getElementById('parah').innerHTML="";
  for (intI=0;intI<arrInput.length;intI++) {
    document.getElementById('parah').innerHTML+=createInput(arrInput[intI], arrInputValue[intI]);
  }
}

function saveValue(intId,strValue) {
  arrInputValue[intId]=strValue;
}  

function createInput(id,value) {
  return "<input type='text' name='"+ id +"_name' onchange='javascript:saveValue("+ id +",this.value)' value='"+ value +"'><br />";
}

function deleteInput() {
  if (arrInput.length > 0) { 
     arrInput.pop(); 
     arrInputValue.pop();
  }
  display(); 
}

above I've got the function:

function createInput(id,value) {
  return "<input type='text' name='"+ id +"_name' onchange='javascript:saveValue("+ id +",this.value)' value='"+ value +"'><br />";
}

Now what I'm trying to do is change the name certain value.

 

I've got a php script which gets data from a database to create a list of inputs:

<?php
$sql = "SELECT * FROM committee WHERE position = 'comm' ORDER BY id ASC";
if ($result = mysql_query($sql)) {
	if (mysql_num_rows($result)) {
		 while ($row = mysql_fetch_assoc($result)) {
			echo " <input type=\"text\" name=\"".$row['id']."_name\" value=\"".$row['name']."\" size=\"15\" />,"; // creates input
		}
  		} else {
   			echo "Sorry, but no results were found found\n";
    		}
	} else {
  		echo "Query failed<br />\n$sql<br />\n".mysql_error()."\n";
  	}
?>

 

basically I need to get the id variable to start at one higher than the last php $row['id'].. I'm not sure that it's possible though.

Link to comment
https://forums.phpfreaks.com/topic/49294-change-javascript-variable-based-on-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.