Cant Submit Form ( Saas, Paas, Iaas) - php

When I try to click on the submit or cancel the form nothing happens.
Here is part of the register_company.php code.
enter code here
<script type="text/JavaScript">
<!--
function getArrays() {
if (validateForm()) {
loadArray('appcatindex');
loadArray('targetindindex');
loadArray('managedservices');
document.getElementById('company').action = "<?php echo BASE_URL_JCM; ?>/save_company.php";
document.getElementById('company').submit();
} else {
return false;
}
}
function loadArray (tcIndex) {
if (document.getElementById(tcIndex) != null) {
lnLength = document.getElementById(tcIndex).length;
} else {
return true;
}
if (tcIndex == 'docindex') {
textDelim = "";
} else {
textDelim = "";
}
var lcIDs = "";
lcDelim = "";
for (var i=0;i<lnLength;i++) {
if (document.getElementById(tcIndex).options[i].selected) {
lcIDs = lcIDs + lcDelim + textDelim + document.getElementById(tcIndex).options[i].value + textDelim;
lcDelim = ",";
}
}
document.getElementById('a'+tcIndex).value = lcIDs;
}
function validateForm() {
lcReturn = "";
lcReturn = lcReturn + checkText('companyName','Company Name');
lcReturn = lcReturn + checkText('firstName','First Name');
lcReturn = lcReturn + checkText('contactEmail','Contact E-mail Address');
lcReturn = lcReturn + checkSelect('appcatindex','Application Categories');
lcReturn = lcReturn + checkSelect('targetindindex','Target Industries');
lcReturn = lcReturn + checkSelect('managedservices','Managed Services');
lcReturn = lcReturn + checkTextArea('hardwareTech','Hardware Technology');
lcReturn = lcReturn + checkTextArea('softwareTech','Software Technology');
lcReturn = lcReturn + checkTextArea('serviceSolution','Service Solutions');
lcReturn = lcReturn + checkTextArea('iaassolution','Infrastructure-as-Service(IaaS) Solution');
lcReturn = lcReturn + checkTextArea('paassolution','Platform-as-Service(PaaS) Solution');
lcReturn = lcReturn + checkTextArea('keyDiff','Key Differentiators');
lcReturn = lcReturn + checkTextArea('sampleCust','Sample Customer Names');
if (lcReturn != "") {
lcReturn = lcReturn + "\nPlease correct these fields and resubmit.";
alert(lcReturn);
return false;
}
return true;
}
function checkTextArea(tcField,tcLabel) {
lctext = "";
if (document.getElementById(tcField)) {
lctest = document.getElementById(tcField).value;
if (lctest.length > 250) {
lctext = tcLabel + " is greater than 250 characters ("+lctest.length+" used).\n";
}
}
return lctext;
}
function checkSelect(tcField,tcLabel) {
lctext = "";
if (document.getElementById(tcField)) {
lnLength = document.getElementById(tcField).length;
var lnSelCnt = 0;
for (var i=0;i<lnLength;i++) {
if (document.getElementById(tcField).options[i].selected) {
lnSelCnt++;
}
}
if (tcField!='appcatindex') {
if (tcField!='targetindindex') {
if (lnSelCnt > 5) {
lctext = tcLabel + " has more than 5 options selected ("+lnSelCnt+" selected).\n";
}
}
}
if (tcField=='appcatindex') {
if (lnSelCnt > <?php echo $saasAppCoLimit ?>)
{
lctext = tcLabel + " has more than <?php echo $saasAppCoLimit ?> options selected ("+lnSelCnt+" selected).\n";
}
}
if (tcField=='targetindindex' ) {
if (lnSelCnt > <?php echo $saasIndCoLimit ?>)
{
lctext = tcLabel + " has more than <?php echo $saasIndCoLimit ?> options selected ("+lnSelCnt+" selected).\n";
}
}
}
return lctext;
}
function checkText(tcField,tcLabel) {
lctext = "";
if (document.getElementById(tcField)) {
lctest = document.getElementById(tcField).value;
if (lctest == "") {
lctext = tcLabel + " is empty. This field is required.\n";
}
}
return lctext;
}
function updateStatus (toOption) {
lcStatus = toOption.value;
lcStatus = lcStatus.substring(0,1);
document.getElementById('status').value = lcStatus;
}
-->
</script>
<div id="divMain" align="center">
<div id="divContent" align="left">
<!--img src="<?php echo DOMAIN_URL ?>/343/images/company.jpg" border="0" width="670px" align="top" -->
<form name='company' id='company' method='post' action=''>
<!-- h3><?php echo $headtitle ?></h3 -->
<input type='button' value='Submit' onclick='getArrays();return false;' /> <input type='button' value='Cancel' onclick='self.close();' />
<input type="hidden" name="companyid" id="companyid" value="<?php echo $companyid ?>"><input type="hidden" name="querytype" id="querytype" value="<?php echo $querytype ?>">
<input type="hidden" name="profiletype" id="profiletype" value="<?php echo $profiletype ?>"><input type="hidden" name="status" id="status" value="<?php echo $status ?>">
<input type="hidden" name="key" id="key" value="<?php echo $key ?>"><input type="hidden" name="createDate" id="createDate" value="<?php echo $createDate ?>">
<input type="hidden" name="updateDate" id="updateDate" value="<?php echo $updateDate ?>"><input type="hidden" name="enablingTech" id="enablingTech" value="<?php echo $enablingTech ?>">
<input type="hidden" name="paas" id="paas" value="<?php echo $paas ?>"><input type="hidden" name="iaas" id="iaas" value="<?php echo $iaas ?>">
<input type="hidden" name="aappcatindex" id="aappcatindex" value=""><input type="hidden" name="atargetindindex" id="atargetindindex" value="">
<input type="hidden" name="amanagedservices" id="amanagedservices" value=""><input type="hidden" name="request_uri" id="request_uri" value="<?php echo $request_uri ?>">
</form>
</div>
</div>
Problem is only related to submit button it does nothing, I googled it but didn't find any posible solution.
Here is the web link http://www.cloudshowplace.com/saas/

You have a </form> tag but no <form> tag. Something like <form action="action_page.php" method="post"> should work. You could also attach javascript actions to the submit button.

Here the answer to my problem.
Changed input type "button" to "submit", and it started working like a charm.
<input type='submit' value='Submit' onclick='getArrays();return false;' />
<input type='submit' value='Cancel' onclick='self.close();' />

Related

Trying to check and send mysql info

<script>
function buttonClick(){
var total = 0;
var type = "";
for(var i=1;i<=3;i++) {
var id = "max_clicks" + i;
var label = "label" + i;
var badge = "badge" + i;
if (document.getElementById(id).checked!=null && document.getElementById(id).checked==true) {
total += parseInt(document.getElementById(id).value);
type +="Max-clicks:<hr style='margin-top:-1px;' />"+ "<span class='badge' style='margin-top:-5px;'>" + document.getElementById("label"+i).innerHTML + "</span> : <span class='badge' style='margin-top:-5px;'>" + document.getElementById("badge"+i).innerHTML + "</span><br />";
}
}
document.getElementById('Totalcost').innerHTML = total;
document.getElementById('individual').innerHTML = type;
}
</script>
<form action="<?php echo "".site_url."";?>/magaza/reklam-ver" method="post" enctype="multipart/form-data">
<input type="checkbox" name="max_clicks[]" id="max_clicks1" value="<?php echo "".$price1."";?>" onClick="buttonClick(this);">
<label id="label1" class="badge" style="background:#fc5a5d;"> 150 clicks</label>-<span class="badge" id="badge1">Price: 5 credits</span><br />
<input type="checkbox" name="max_clicks[]" id="max_clicks2" value="<?php echo "".$price2."";?>" onClick="buttonClick(this);">
<label id="label2" class="badge" style="background:#fc5a5d;"> 400 clicks</label>-<span class="badge" id="badge2">Price: 13 credits</span><br />
<input type="checkbox" name="max_clicks[]" id="max_clicks3" value="<?php echo "".$price3."";?>" onClick="buttonClick(this);">
<label id="label3" class="badge" style="background:#fc5a5d;"> 735 clicks</label>-<span class="badge" id="badge3">Price: 9 credits</span><br />
<span id="individual" class="badge" style="background:#f29d9d;">You dont have any select item.</span>
<button type="button"class="btn btn-primary" onclick="buttonClick()">Price to pay:
<span class="badge"><span id="Totalcost">0</span> credits</span></button>
<input class="btn btn-success" style="float:right;" type="submit" name="add_ad" value="Reklam satın al">
</form>
I trying to get checked item and send to mysql... All working but have problem with send to mysql i want to send max-click -info of <span>....</span> and check price with input value and send this to mysql - max-clicks -value off <span>..</span> and value of input any ideas ? i give my script form.php and action_form.php and sorry for my language :/
if($_POST['add_ad'])
{
if(!empty($_POST['max_clicks'])) {
$shipping_subtotal = 0;
foreach($_POST['max_clicks'] as $shipping){
$shipping_subtotal += $shipping;
}
$user = userInfo();
if($user['credits'] >= $shipping_subtotal){ //check user have enough credits or not
if($_POST['title'] && $_POST['target_url'])
{
$expires = strtotime("+1 month"); //Reklam 1 ay ekle
$title = quote_smart($_POST['title']);
$target_url = quote_smart($_POST['target_url']);
mysql_query("INSERT INTO ads (date_added,date_expires, target_url, clicks, author_id, title, max_clicks) VALUES ('".time()."',$expires, $target_url, '0', '".$_COOKIE['user_id']."', $title, $shipping_subtotal)") or die(mysql_error());
echo info("Success!");
delcredits($user['id'], $shipping_subtotal);
header ("refresh:3;url=".site_url."/magaza/reklam-ver");
}
else
{
echo error("Error.");
}
}
else
{
echo error("you dont have enough credits");
}
}
else{
echo "<b>Please select max-clicks.</b>";
}
}

PHP CRUD - Update function

I am creating the BindableCollection class which implements IBindableCollection.
What I want to do is CRUD operations above the collection (array of associative arrays). I have all of the CRUD functionallity, but I lack update function which doesn't work.
Code
public function updateFirstWhere($attr, $value, $updateCallback) {
$i = 0;
foreach($this->value as $data) {
if($data[$attr] == $value) {
call_user_func_array($updateCallback, $this->value[$i]);
return;
}
$i++;
}
}
When I pass the $this->value[$i] (which is all of the data inside collection) to the callback function and I do something like that:
public function deleteThePerson($sender) {
$this->collection->updateFirstWhere("id", $sender->data_id, function(&$data) {
$data["name"] = "durisvk";
});
}
I don't see the change in the data.
I want to set the name to durisvk but I can't.
Any Ideas Please?
</head>
<body>
<?php
// UPDATE CRUD element.
$idc = -1;
$naam = "";
$merk = "";
$typ = "";
$kl = "";
$con = new PDO ("mysql:host=localhost;dbname=cars_database", "root", "");
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if(isset($_GET["action"])) {
if($_GET["action"] == "edit") {
if($_SERVER["REQUEST_METHOD"] == "POST") {
$statement = $con->prepare("UPDATE cars_assigment SET Name=?, Brand=?, Type=?, Color=? WHERE Id = ?");
$statement->bindValue(1, $_POST["Name"]);
$statement->bindValue(2, $_POST["Brand"]);
$statement->bindValue(3, $_POST["Type"]);
$statement->bindValue(4, $_POST["Color"]);
$statement->bindValue(5, $_POST["Id"]);
$statement->execute();
}
$statement = $con->prepare("SELECT * FROM cars_assigment WHERE Id = ?");
$statement->bindValue(1, $_GET["Id"]);
$statement->execute();
$record = $statement->fetchObject();
if($record != false) {
$idc = $record-> Id;
$naam = $record-> Name;
$merk = $record-> Brand;
$typ = $record-> Type;
$kl =$record-> Color;
}
}
}
?>
<h1> Update </h1>
<form method="POST">
ID: <input type="text" name="Id" value="<?php echo $idc ?>">
Naam: <input type="text" name="Name" value="<?php echo $naam ?>">
Brand: <input type="text" name="Brand" value="<?php echo $merk ?>">
Type: <input type="text" name="Type" value="<?php echo $typ ?>">
Color: <input type="text" name="Color" value="<?php echo $kl ?>">
<input name="Id" type="hidden" value="<?php echo $idc; ?>"> </input>
<input type="submit" value="Save"> </input>
</form>
</body>

How can I submit form using ajax

I want to show the output of polldemo1.php on poll.php page. But it is not happening. It is showing the poll.php page's form again as output.
Please correct it.Also if anyone can explain me php with ajax, it would be really nice
poll.php
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
</head>
<body>
<h3>SIG Polls</h3>
<form method="POST" id="myform" class="myform" >
C/C++
<input type="checkbox" name="vote[]" value="0" />
<br />
Java
<input type="checkbox" name="vote[]" value="1" />
<br />
Matlab
<input type="checkbox" name="vote[]" value="2" />
<br />
C#/.NET
<input type="checkbox" name="vote[]" value="3" />
<br />
PHOTOSHOP
<input type="checkbox" name="vote[]" value="4" />
<br />
CCNA
<input type="checkbox" name="vote[]" value="5" />
<br />
BASIC ELECTRONICS
<input type="checkbox" name="vote[]" value="6" />
<br />
<input type="submit" name="submit" value="vote" onclick="return submitForm()" />
</form>
<div id="myResponse"></div>
<script type="text/javascript">
function submitForm() {
var form = document.myform;
var dataString = $(form).serialize();
$.ajax({
type:'POST',
url:'polldemo1.php',
data: dataString,
success: function(data){
$('#myResponse').text(data);
}
});
return false;
}
</script>
</body>
</html>
polldemo1.php
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
</head>
<?php
echo "hello";
//error_reporting(0);
if(isset($_POST['submit']))
{
/*if (isset($_COOKIE["ieeepoll"]))
{
echo "<script>alert('You have already voted'); location.href='poll.php';</script>";
} */
//get content of textfile
$filename = "poll_result.txt";
$content = file($filename);
//put content in array
$array = explode("||", $content[0]);
$c = $array[0];
$java = $array[1];
$matlab = $array[2];
$net = $array[3];
$ph = $array[4];
$ccna = $array[5];
$be = $array[6];
foreach($_POST["vote"] as $vote)
{
if ($vote == 0)
{
$c = $c + 1;
}
if ($vote == 1)
{
$java = $java + 1;
}
if ($vote == 2)
{
$matlab = $matlab + 1;
}
if ($vote == 3)
{
$net = $net + 1;
}
if ($vote == 4)
{
$ph = $ph + 1;
}
if ($vote == 5)
{
$ccna = $ccna + 1;
}
if ($vote == 6)
{
$be = $be + 1;
}
}
//insert votes to txt file
$insert = $c."||".$java."||".$matlab."||".$net."||".$ph."||".$ccna."||".$be;
file_put_contents($filename,$insert);
echo $be;
}
?>
Add onsubmit event in for html form attribute as following
<form method="POST" id="myform" class="myform" onsubmit="return false" >
You can manage above thing by jQuery also, just need to modify your javascript code something like this.
$("#myform").on('submit', function (event) {
event.preventDefault();
$.ajax({
type: 'POST',
url: 'polldemo1.php',
data: $("#myform").serialize(),
success: function (data, status) {
//do whatever you want to do
},
error: function (err) {
//do wahtever you want to do
}
});
});
//OR
$("#myform").on('submit', function (event) {
event.preventDefault();
submitForm();
});
Also you don't need to keep any html attribute in you php script. Remove all html tags from that script.
try this it should help you.it will display the content of the file on poll.php on submit of form.
poll.php
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
</head>
<body>
<h3>SIG Polls</h3>
<form method="POST" id="myform" class="myform" >
C/C++
<input type="checkbox" name="vote[]" value="0" />
<br />
Java
<input type="checkbox" name="vote[]" value="1" />
<br />
Matlab
<input type="checkbox" name="vote[]" value="2" />
<br />
C#/.NET
<input type="checkbox" name="vote[]" value="3" />
<br />
PHOTOSHOP
<input type="checkbox" name="vote[]" value="4" />
<br />
CCNA
<input type="checkbox" name="vote[]" value="5" />
<br />
BASIC ELECTRONICS
<input type="checkbox" name="vote[]" value="6" />
<br />
<input type="submit" name="submit" value="vote" onclick="return submitForm()" />
</form>
<div id="myResponse"></div>
<script type="text/javascript">
function submitForm() {
var dataString = $("#myform").serialize();
$.ajax({
type:'POST',
url:'index.php',
data: dataString,
success: function(data){
$('#myResponse').text(data);
}
});
return false;
}
</script>
</body>
</html>
polldemo1.php
<?php
echo "hello";
//error_reporting(0);
if(isset($_POST))// do not check for submit here it won't go with post
{
/*if (isset($_COOKIE["ieeepoll"]))
{
echo "<script>alert('You have already voted'); location.href='poll.php';</script>";
} */
//get content of textfile
$filename = "poll_result.txt";
$content = file($filename);
//put content in array
$array = explode("||", $content[0]);
$c = $array[0];
$java = $array[1];
$matlab = $array[2];
$net = $array[3];
$ph = $array[4];
$ccna = $array[5];
$be = $array[6];
foreach($_POST["vote"] as $vote)
{
if ($vote == 0)
{
$c = $c + 1;
}
if ($vote == 1)
{
$java = $java + 1;
}
if ($vote == 2)
{
$matlab = $matlab + 1;
}
if ($vote == 3)
{
$net = $net + 1;
}
if ($vote == 4)
{
$ph = $ph + 1;
}
if ($vote == 5)
{
$ccna = $ccna + 1;
}
if ($vote == 6)
{
$be = $be + 1;
}
}
//insert votes to txt file
$insert = $c."||".$java."||".$matlab."||".$net."||".$ph."||".$ccna."||".$be;
file_put_contents($filename,$insert);
echo $insert;
}
?>

Ajax with PHP and HTML

<input type="button" value="addkid " onClick="show()" />
<div>
<div id="myTableData" style="display:none; width:800px; height:500px; background-color:yellow; margin:0 auto;">
<form action="javascript:insert()" method="get">
<table>
<tr>
<td width="175">NAME</td>
<td width="245"> Gender</td>
<td width="245">Date of Birth</td>
</tr>
<tr>
<td width="175">
<input type="text" name="kid_name" id="kid_name" />
</td>
<td width="245">FEMALE
<input type="radio" name="gender" value="female" id="gender" />MALE
<input type="radio" name="gender" id="gender" value="male" />
</td>
<td width="245">
<?php for ( $i=1; $i<13; $i++ ) { $month=d ate( 'm', mktime(0,0,0,$i,2,2000)); $sel=( $i==d ate( 'n') ? ' selected="selected"' : ''); $options1[]="<option value=\" {$month}\ " {$sel}>{$month}</option>"; } $options_list1=j oin( "", $options1); echo "<select name=\"month\ " id='month' >{$options_list1}</select>"; for ( $j=1; $j<32; $j++ ) { $theday=d ate( 'd', mktime(0,0,0,0,$j,2000)); $sel=( $j==d ate( 'd') ? ' selected="selected"' : ''); $options2[]="<option value=\" {$theday}\ " {$sel}>{$theday}</option>"; } $options_list2=j oin( "\r\n", $options2); echo "<select name=\"day\ " id='day' >{$options_list2}</select>"; for ( $k=1960; $k<2016; $k++ ) { $theyear=d ate( 'Y', mktime(0,0,0,1,1,$k)); $sel1=( $k==d ate( "Y") ? ' selected="selected"' : ''); $options3[]="<option value=\" {$theyear}\ " {$sel1}>{$theyear}</option>"; } $options_list3=j oin( "\r\n", $options3); echo "<select name=\"year\ " id='year' >{$options_list3}</select>"; ?>
</td>
</tr>
</table>
<input type="submit" name="sub" value="add" />
</form>
</div>
</div>
<script>
function show() {
document.getElementById("myTableData").style.display = "block";
}
function createObject() {
var request_type;
var browser = navigator.appName;
if (browser == "Microsoft Internet Explorer") {
request_type = new ActiveXObject("Microsoft.XMLHTTP");
} else {
request_type = new XMLHttpRequest();
}
return request_type;
}
var http = createObject();
//value solve an Internet Explorer cache issue
var nocache = 0;
function insert() {
// Optional: Show a waiting message in the layer with ID login_response
document.getElementById('content02').innerHTML = "Just a second..."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var kid_name = encodeURI(document.getElementById('kid_name').value);
var gender = encodeURI(document.getElementById('gender').value);
var month = encodeURI(document.getElementById('month').value);
var day = encodeURI(document.getElementById('day').value);
var year = encodeURI(document.getElementById('year').value);
// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http.open('get', '4.php?kid_name=' + kid_name + '&gender=' + gender + '&month=' + month + '& day=' + day + '&year=' + year + '&nocache = ' + nocache);
http.onreadystatechange = insertReply;
http.send(null);
}
function insertReply() {
if (http.readyState == 4) {
var response = http.responseText;
// else if login is ok show a message: "Site added+ site URL".
document.getElementById('content02').innerHTML = 'Your contact was successfully added!' + response;
}
}
</script>
4.php
<?php
if(isset($_GET['kid_name']) && isset($_GET['gender']) && isset($_GET['year']) && isset($_GET['day']) && isset($_GET['month']) )
{
echo $newFname = $_GET["kid_name"] ;
echo $newLname = $_GET["gender"] ;
echo $newPhone = $_GET["year"] ;
echo $newEmail = $_GET["day"] ;
echo $newAddress = $_GET["month"] ;
//$insertContact_sql = "INSERT INTO `test`.`contacts` (`newFname`, `newLname`, `newPhone`, `newEmail`, `newAddress`, `group`) VALUES ('{$newFname}' , '{$newLname}' , '{$newPhone}' , '{$newEmail}' , '{$newAddress}' , '{$group}')";
//$insertContact= mysql_query($insertContact_sql) or die(mysql_error());
} else
{
echo 'Error! Please fill all fileds!';
}
?>
I am working with php language. There is a addkid button, which, when the user clicks on the button a pop type window shows the form which has NAME , GENDER AND DOB. In the form action javascript:insert(). I am using ajax for the 1st time so I am not able to understand why it's not working. I guess it should redirect me to 4.php and in 4.php it will echo the values?
I have tested your code and seems it works, I just added a div to show the results there...
You can try to add this div you are not already added it...
<div id="content02">
</div>
Here you write the response, like "Your contact was successfully added"....

Two loops mixed up

I have this code, I have removed some code that has nothing to do with my problem.
while ($row_pl = mysql_fetch_array($res_pl))
{
// Uurtarief
$sql_uur = "SELECT
aantal_kop,
tarief_min,
tarief_max,
tijd_min,
tijd_max,
tijd_extra
FROM uurtarief
WHERE machine = '".$row_pl['machine']."'
ORDER BY aantal_kop ASC";
if(!$res_uur = mysql_query($sql_uur))
{
include('includes/errors/database_error.php');
}
else
{
while ($row_uur = mysql_fetch_array($res_uur))
{
?>
<input type="text" name="tar_kop[]" size="8" value="<?php echo $row_uur['aantal_kop']; ?>" />
<input type="text" name="tar_tarief[]" size="8" value="<?php echo $uurtarief; ?>" />
<input type="text" name="tar_tijd_extra[]" size="8" value="<?php echo $row_uur['tijd_extra']; ?>" />
<br />
<?php
}
}
?>
<tr>
<td>
<input type="text" name="pl_aantal_kop[]" size="3" onChange="uur_tarief(this, <?php echo $i ?>)" value="" />
</td>
<td>
<input type="text" name="pl_tarief_ph[]" size="4" value="" />
</td>
</tr>
<?php
}
With javascript I'm trying to find the value in pl_aantal_kop[] and send the corresponding parameter to pl_tarief_ph[]
function uur_tarief(selectVeld, nr)
{
if(document.getElementsByName('pl_aantal_kop[]')[nr].value == 1)
{
document.getElementsByName('pl_tarief_ph[]')[nr].value = document.getElementsByName('tar_tarief[]')[0].value;
document.getElementsByName('pl_snijtijd_extra[]')[nr].value = document.getElementsByName('tar_tijd_extra[]')[0].value;
}
if(document.getElementsByName('pl_aantal_kop[]')[nr].value == 2)
{
document.getElementsByName('pl_tarief_ph[]')[nr].value = document.getElementsByName('tar_tarief[]')[1].value;
document.getElementsByName('pl_snijtijd_extra[]')[nr].value = document.getElementsByName('tar_tijd_extra[]')[1].value;
}
if(document.getElementsByName('pl_aantal_kop[]')[nr].value == 3)
{
document.getElementsByName('pl_tarief_ph[]')[nr].value = document.getElementsByName('tar_tarief[]')[2].value;
document.getElementsByName('pl_snijtijd_extra[]')[nr].value = document.getElementsByName('tar_tijd_extra[]')[2].value;
}
if(document.getElementsByName('pl_aantal_kop[]')[nr].value == 4)
{
document.getElementsByName('pl_tarief_ph[]')[nr].value = document.getElementsByName('tar_tarief[]')[3].value;
document.getElementsByName('pl_snijtijd_extra[]')[nr].value = document.getElementsByName('tar_tijd_extra[]')[3].value;
}
if(document.getElementsByName('pl_aantal_kop[]')[nr].value == 5)
{
document.getElementsByName('pl_tarief_ph[]')[nr].value = document.getElementsByName('tar_tarief[]')[4].value;
document.getElementsByName('pl_snijtijd_extra[]')[nr].value = document.getElementsByName('tar_tijd_extra[]')[4].value;
}
if(document.getElementsByName('pl_aantal_kop[]')[nr].value == 6)
{
document.getElementsByName('pl_tarief_ph[]')[nr].value = document.getElementsByName('tar_tarief[]')[5].value;
document.getElementsByName('pl_snijtijd_extra[]')[nr].value = document.getElementsByName('tar_tijd_extra[]')[5].value;
}
}
The problem that occurred is that the javascript keeps starting counting at the first line of the while ($row_uur = mysql_fetch_array($res_uur)) loop instead of the field that belongs to the first loop. Below an screenshot of this loop.
Any suggestions?
You can condense your JS to this:
function uur_tarief(selectVeld, nr)
{
var index = document.getElementsByName('pl_aantal_kop[]')[nr].value;
document.getElementsByName('pl_tarief_ph[]')[nr].value = document.getElementsByName('tar_tarief[]')[index - 1].value;
document.getElementsByName('pl_snijtijd_extra[]')[nr].value = document.getElementsByName('tar_tijd_extra[]')[index - 1].value;
}
Can you try this code and post back? Where are you initializing and calling the JavaScript code? The code you posted looks fine (although bloated severely), so it might be an issue elsewhere.

Categories