Jump to content

Recommended Posts

Hey all,

I have a radio button for each table row with a value corresponding to the row, I then have two hrefs  edit/delete which goes to different pages.

 

What i want to do is send the corresponding clicked radio button value with either the edit or delete href. At the moment im trying to send the value through the url using the get method but the value doesnt pass to the url once clicked.

 

How can i instantly validate a radio button clicked on the default page so i can send it through to the url before its clicked?

 

The variable i want to send through the radio button value is $row

 

Note: This is not the whole script only the loop that creates the radio buttons and hrefs. So the form tags etc are all included in the whole script.

 

function row_loop(){
	$rownum = 0;
	$row = 1;
	for($currentrow=0; $currentrow < $_SESSION['rows']; $currentrow++){
	echo "<tr>";
	echo "<td><input type='radio' name='rowid' value='$row'></td>";
	foreach($_SESSION['colid'] as &$value){
		$column = mysql_query("SELECT $value FROM weight_con ORDER BY UID");
		$data = mysql_result($column, $rownum);
		if(empty($data)){
			echo "<td></td>";
		}else{
		echo "<td>".$data."</td>";
		}
	}
	echo "</tr>";
	$rownum++;
	$row++;
	}
	echo "</table>";
	add_unit($row);
}



function add_unit($row){
echo "<a href='edit_row.php'>Edit</a> / <a href='index.php'>Delete</a>";
echo "</form>";


}

 

This is what it looks likes to give an idea of what i mean :P

4eeb42aeec8d83711500000.jpg

You need a JS function to do it. This function might be called from "onclick" for every radio-button, also add value of radio as a parameter to the function. Inside this function you have to create and set a new URL for Edit or Delete.

I unfortunetly dont know js, but from other validators ive seen around im sure its not to hard to modify one with a bit of work.

 

I use this one to send new column name to another page but dont know how to modify for multipule radio buttons

 

<script type="text/javascript">
function ftest(){
window.location="add_row.php?name="+document.getElementById('name').value;
}
function getRadioValue(id) {
var radioBtn = document.getElementById(id);
}
</script>

OK...

 

I give you one of my functions which is solving the same task: creation of a correct link according to parameters that user entered.

 

JS:

function set_correct_reference()
{
    var date_process=document.getElementById( 'date_process' ).value;
    var date_process_end=document.getElementById( 'date_process_end' ).value;
    var load_stat_day=document.getElementById( 'load_stat_day' );
    var period_count=document.getElementById( 'period_count' ).value;
    var load_alc=document.getElementById( 'load_alcatel' );
    var load_alc_sim_eric=document.getElementById( 'load_alc_sim_eric' );
    var summary=document.getElementById( 'final_summary' );
    var util=document.getElementById( 'final_util' );
    var top20=document.getElementById( 'final_top20' );
    var final_load=document.getElementById( 'final_load' );

    
    if( period_count != 1 && period_count != 7 ) period_count=1;
    
    load_stat_day.href='load_stat_day_manual.php?date='+date_process;
    load_stat_day.title=load_stat_day.href;
    load_alc.href='load_stat_day.php?what=alcatel&date='+date_process;
    load_alc_sim_eric.href='load_stat_day.php?what=newinfo&date='+date_process+'&summary&util&top20';
    
    final_load.href='load_stat_day.php?date='+date_process;
    if( summary.checked ) final_load.href += '&summary';
    if( util.checked ) final_load.href += '&util';
    if( top20.checked ) final_load.href += '&top20';
    if( !summary.checked && !util.checked && !top20checked ) final_load.href = '';
}

 

HTML:

Dates from <input  type="text" name="date_process" id="date_process" value="YYYY-MM-DD" onkeyup="set_correct_reference(); " size="15" />
to <input  type="text" name="date_process_end" id="date_process_end" value="YYYY-MM-DD" onkeyup="set_correct_reference(); " size="15" /> 
....
    <a id="load_alcatel" href="load_stat_day.php?what=alcatel" onclick="return confirm('Start processing Alcatel-specific data for  '+document.getElementById('date_process').value+'?' )" target="_blank">Prepare Alcatel-specific data
</a>
....
  <input type="checkbox" id="final_top20" checked="checked" onclick="set_correct_reference();" /> <label> Count TOP-20 </label><br />
  <a href="" id="final_load" target="_blank" onclick="return confirm('Are you sure you want to start process for '+document.getElementById('date_process').value+'?')"> Start processing of all data according to selected parameters </a>
...

 

All that you need - (1) to understand this code and (2) adapt it for your needs.

 

As you see (or as you might see :)) when use change some parameters in any input kind many links are changed. User may enter text, set or unset checkboxes - all this actions a reflected immediately in that links.

 

I hope it will help you.

 

PS. Of course, I call function set_correct_reference() for the first time just when my page is loaded.

thanks for posting that code but i found this javascript code last night before i saw this post and have got it to alert the result once button is clicked but i need to know how to now send that radio variable thru the button url via onclick.

 

Example:

<input type=button value='Edit' onclick='location.href=\"edit_row.php?row=javascript:getRadioValue(value)\"'>

 

This is of course wrong as Ive now been working with js for 3 hours.

 

code:

 

    function getRadioValue(radioObject) {
          var value = null
          for (var i=0; i<radioObject.length; i++) {
               if (radioObject[i].checked) {
                    value = radioObject[i].value;
                    break ;
               }
          }
          return value
     }

echo "<td><input type='radio' id='rowid' value='".$row."' name='row'></td>";

echo "<input type=button value='Edit' onclick="[b]Unknown_JS_Code[/b]">";

 

Resolved:

 

Found the code i was looking for javascript now looks like soo.

<script type="text/javascript">
function radio(radioObject) {
var value = null
for (var i=0; i<radioObject.length; i++) {
	 if (radioObject[i].checked) {
		  value = radioObject[i].value;
		  document.links["editlink"].href = "edit_row.php?rowid="+radioObject[i].value;
		  document.links["deletelink"].href = "index.php?delete="+radioObject[i].value;
		  break ;
	 }
}
return value
}
</script>

 

was looking for "document.links["deletelink"].href" i think i now have a new love for javascript really makes forms and submissions easy.

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.