Jump to content

[SOLVED] Need help javascript posting vars


Rodis

Recommended Posts

Hello,

 

I am stuck for a few weeks now. i have a form that gets categorie's out of a database when i fill in the form and change the categorie the subcategorie changes to This is done by a javascript onchange and refresh the url so i can use the get to define which subcategorie belong to the categorie

 

<SCRIPT language=JavaScript>
<!--
function changecat(newcat) {
    exit=false;
    site = "index.php?option=link_toevoegen&cat="+(newcat);
    if (newcat!=0) {
    document.newlink.submit();
	top.location.href=site;
    } else {
    document.newlink.submit();
	top.location.href="index.php?option=link_toevoegen";
    }
}
-->	
</SCRIPT>

 

The problem here is that all the fields i filled in are empty again.

 

I thought this could be solved by adding a submit to the script so i can retreive the posted info into the fields again except nothing gets posted. Can someone help me and tell me how to keep the values in the form when i change categorie

Below my full test code.

 

<SCRIPT language=JavaScript>
<!--
function changecat(newcat) {
    exit=false;
    site = "index.php?option=link_toevoegen&cat="+(newcat);
    if (newcat!=0) {
    document.newlink.submit();
	top.location.href=site;
    } else {
    document.newlink.submit();
	top.location.href="index.php?option=link_toevoegen";
    }
}
-->	
</SCRIPT>
<?php

// Dit word een taal bestandje
// define woorden bij link toevoegen.
define('CATEGORY', 'Categorie*');
define('SUBCATEGORY','Subcategorie');
define('LANGUAGE_SITE', 'Taal');
define('NAME_LINK','Naam*');
define('LINK_URL','Link*');
define('DESCRIPTION','Omschrijving');
define('TIP','Tip');
define('KEYWORDS','Sleutelwoorden*');
define('DAY','Dag');
define('MONTH','Maand');
define('YEAR','Jaar');
define('EMAIL','Email');
define('NOTES','Opmerkingen');
define('BUTTON_SUBMIT','Toevoegen');
define('DATANEWLINK','Gegevens nieuwe link:');
define('STARFIELD','*Velden met een sterretje zijn verplicht');
define('EXPIREDATE','Verloop datum:');
define('MAXDATE','Max tot 1 januari 2038');
define('DATA_ADVERTISER','Gegevens adverteerder:');
define("AFFILIATE","Affiliate");

?>
<?php
function categorie(){
if (isset($_GET['cat'])){
	$cat = $_GET['cat'];
	}else {
		$cat = "";
	}
$db = new db_connect();
$db->select = "SELECT c_naam,c_id FROM sb_link_categorie ORDER BY c_naam asc"; 
$db->selectQuery(); 
	while($row = $db->getRows()) {
		if ($cat == $row['c_naam']) {$selected = "selected";}else {$selected = "";}  
		$option = "<option $selected id=".$row['c_naam']." value=".$row['c_id'].">".$row['c_naam']."</option>"; 
		$result .= $option;
		}
		return $result;
}

function subcategorie(){
if (isset($_GET['cat'])){
	$categorie = $_GET['cat'];
	}else {
		$categorie = "";
	}
$db = new db_connect();
$db->select = "SELECT s_naam FROM sb_link_subcat WHERE c_naam = '$categorie' ORDER BY s_naam ASC";
$db->selectQuery();
	while ($row =$db->getRows()){
	$option = "<option value='".$row['s_naam']."'>".$row['s_naam']."</option>";
	$result .= $option;
	}
	return $result;
}

function taal(){

$db = new db_connect();
$db->select = "SELECT * FROM sb_link_taal ORDER BY waarde ASC";
$db->selectQuery();
	while ($row = $db->getRows()){
		$select = "nl";
		if ($select == $row['taal']) {$selected = "selected";}else {$selected = "";}
		$option = "<option $selected value='".$row['taal']."'>".$row['waarde']."</option>";
		$result .= $option;
	}
	return $result;
}

function affiliate(){

$db = new db_connect();
$db->select = "Select * FROM sb_admin_affiliates ORDER BY waarde ";
$db->selectQuery();
	while ($row = $db->getRows()){

		$option = "<option value='".$row['id']."'>".$row['waarde']."</option>";
		$result .= $option;
	}
	return $result;
}

//vanaf hier gaan we zorgen dat bij cat wijzigen de inhoud blijft
if (isset($_POST['naam'])){$naam = $_POST['naam'];}else{$naam = "";}
if(isset($_POST['submit'])){
$_SESSION['naam'] = $_POST['naam'];
echo $_SESSION['naam'];
}
?>
<table>
  <tr>
<td>
<p><? echo STARFIELD ?></p>
</td>
  </tr>
</table>
<form name="newlink" method="post" action="index.php?option=link_schrijven&action=toevoegen">
<table width="100%"  cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="3"><div align="center"><strong><? echo DATANEWLINK ?></strong></div></td>
  </tr>
  <tr>
    <td><? echo CATEGORY ?></td>
    <td><strong>:</strong></td>
    <td><select name="categorie" onChange="changecat(this.options[this.selectedIndex].id)">
      <option></option>
      <? echo categorie(); ?>
    </select></td>
  </tr>
  <tr>
    <td><? echo SUBCATEGORY ?></td>
    <td><strong>:</strong></td>
    <td><select name="subcategorie" onChange="MM_jumpMenu('parent',this,0)">
      <option></option>
      <? echo subcategorie(); ?>
    </select></td>
  </tr>
  <tr>
    <td><? echo LANGUAGE_SITE ?></td>
    <td><strong>:</strong></td>
    <td><select name="taal" onChange="MM_jumpMenu('parent',this,0)">
      <? echo taal() ?>
    </select></td>
  </tr>
  <tr>
    <td><? echo NAME_LINK ?></td>
    <td><strong>:</strong></td>
    <td><input type="text" name="naam" size="50" value="<? $naam ?>"></td>
  </tr>
  <tr>
    <td><? echo LINK_URL ?></td>
    <td><strong>:</strong></td>
    <td><input type="text" name="link" size="100"></td>
  </tr>
  <tr>
    <td valign="top"><? echo DESCRIPTION ?></td>
    <td valign="top"><strong>:</strong></td>
    <td>
      <textarea name="omschrijving" cols="80" rows="15"></textarea>	</td>
  </tr>
  <tr>
    <td><? echo TIP ?></td>
    <td><strong>:</strong></td>
    <td><select name="tip" onChange="MM_jumpMenu('parent',this,0)">
      <option selected value="False">nee</option>
      <option value="True">Ja</option>
    </select></td>
  </tr>
  <tr>
    <td><? echo KEYWORDS ?></td>
    <td><strong>:</strong></td>
    <td><input type="text" name="keywords" size="105"></td>
  </tr>
  <tr>
    <td colspan="3"><div align="center"><strong><? echo EXPIREDATE ?></strong></div></td>
  </tr>
  <tr>
    <td><span class="style1"><? echo MAXDATE ?></span></td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td><? echo DAY ?></td>
    <td><strong>:</strong></td>
    <td><input type="text" name="dag" size="50"></td>
  </tr>
  <tr>
    <td><? echo MONTH ?></td>
    <td><strong>:</strong></td>
    <td><input type="text" name="maand" size="50"></td>
  </tr>
  <tr>
    <td><? echo YEAR ?></td>
    <td><strong>:</strong></td>
    <td><input type="text" name="jaar" size="50"></td>
  </tr>
  <tr>
    <td colspan="3"><div align="center"><strong><? echo DATA_ADVERTISER ?></strong></div></td>
  </tr>
  <tr>
    <td><? echo EMAIL ?></td>
    <td><strong>:</strong></td>
    <td><input type="text" name="email" size="50"></td>
  </tr>
    <tr>
    <td><? echo AFFILIATE ?></td>
    <td><strong>:</strong></td>
    <td><select name="affiliate" onChange="MM_jumpMenu('parent',this,0)">
      <option></option>
      <? echo affiliate(); ?>
    </select></td>
  </tr>
  <tr>
    <td valign="top"><? echo NOTES ?></td>
    <td valign="top"><strong>:</strong></td>
    <td><textarea name="opmerking" cols="80" rows="5"></textarea></td>
  </tr>
  <tr>
    <td colspan="3"><div align="center">
      <input name="Submit" type="submit" value="<? echo BUTTON_SUBMIT ?>">
    </div></td>
    </tr>
</table>
</form>

Link to comment
Share on other sites

Fixed code:

 

function changecat(newcat) {
       exit=false;
       site = "index.php?option=link_toevoegen&cat="+(newcat);
       if (newcat!==0) {
       document.newlink.submit();
      top.location.href=site;
       } else {
       document.newlink.submit();
      top.location.href="index.php?option=link_toevoegen";
       }
   }

Link to comment
Share on other sites

Fixed code:

 

function changecat(newcat) {
       exit=false;
       site = "index.php?option=link_toevoegen&cat="+(newcat);
       if (newcat!==0) {
       document.newlink.submit();
      top.location.href=site;
       } else {
       document.newlink.submit();
      top.location.href="index.php?option=link_toevoegen";
       }
   }

 

Hey thanks for your reply's but i can't see any difference in the fixed code except for the fact that there are less spaces in the 2 lines. Anyways this still doesn't work my script only changes the url on the onchange effect which is good cause it makes me get the right subcategories from the cats but i need it to submit my values already filled in and post them to the new url to so i can keep the values in the texterea's before submitting them to the database. each time i change the categorie the fields are emptied since the page is refreshed to. If i can get the script to post i can retreive the values and problem would be solved

Link to comment
Share on other sites

so the category thing is fixed but the submit thing dont work ???

 

ok halfway there. anyhow i just checked your JS on 3 different debuggers and nothing came up, got a link so i can test it out? otherwise i would say its out of my league i would have to let the regulars in here like rhodesea or MAQ help you out  :-\

Link to comment
Share on other sites

Whell thanks anyway if you can't help me.

 

I have tried several things and if i loose the location bit values do get submitted , but then i won't be able to get the categorie out of the url so the subcategories are displayed right. since it won't be dericted to the new url. it seems that only one is working at a time.

 

i have tried to change the submit part in hope it wil submit to site url but no luck and can't seem to find anything about in on the internet they eiterh submit or change url not both in one :-( I don't know how else is should do it

Link to comment
Share on other sites

Woowie i have found it i tried all weird things and combos like top.submit.location.href=site(); and so on turns out to be simple.

 

2 object in a fucntion only works foor the last one it seems but for since this may be usefull for others i got it working with this.

function changecat(newcat) {
    exit=false;
    site = "index.php?option=link_toevoegen&cat="+(newcat);
    if (newcat!=0) {
    document.newlink.action=site;
	document.newlink.submit();	
    } else {
	document.newlink.action="index.php?option=link_toevoegen";
	document.newlink.submit();
    }
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.