Formular mit Textlink ansprechen

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Formular mit Textlink ansprechen

    Code:
    <script language="javascript">
    function doit(action,req) {
    	if (!document.meinForm) return;
    	if (req != 1) {
    		var selection = 0;
    		if (document.meinForm.id.length) {
    			for (i = 0; i < document.meinForm.id.length; i++) {
    				if (document.meinForm.id[i].checked) selection = 1;
    			}
    		}else{
    		        if (document.meinForm.id.checked) selection = 1;
    		}				
    		if (!selection == 1) {
    			alert("Es muss mindestens ein Eintrag ausgewählt sein.");
    			return;
    		}		
    	}
    	this.location.href= ('datei_' + action+ '.php?action=edit&id='+ document.meinForm.id.value);
    }
    </script>
    </head>
    <body>
    <form name="meinForm" method="get" action="">
      <input type="radio" name="id" value="1"><br>
      <input type="radio" name="id" value="2"><br>
      <input type="radio" name="id" value="3"><br>
      <input type="radio" name="id" value="4"><br>
      <input type="radio" name="id" value="5"><br>
      <br>
      <a href="JavaScript:doit('delete')">l&ouml;schen</a> 
    <a href="JavaScript:doit('rename')">umbenennen</a> 
    <a href="JavaScript:doit('edit')">editieren</a> 
    <a href="JavaScript:doit('copy')">kopieren</a> 
    <a href="JavaScript:doit('move')">verschieben</a> 
    
    </form>
    Hallo,

    Ich möcht mit Textlinks auf das Formular zugreifen und was markiert ist die entsprechende ID auf eine URL weiter komme in form in etwa wie es oben ist.
    Was dabei nicht hinhaut ist das bei der URL stoppt es und auch liest er nicht die ID aus. Was mache ich dort falsch?

    Gruss


    Björn
    Last edited by joker-22; 26-12-2005, 18:26.

  • #2
    Dein Fehler ist ein ziemlich doofer Fehler :P Aber so sollte es gehen:
    PHP Code:
    <script language="javascript">
    function 
    doit(action,req
    {
        var 
    selectedIDX null;
        if (!
    document.meinForm) return;
        if (
    req != 1
        {
            var 
    selection 0;
            if (
    document.meinForm.id.length
            {
                for (
    0document.meinForm.id.lengthi++) 
                {
                    if (
    document.meinForm.id[i].checked)
                    {
                        
    selection 1;
                        
    selectedIDX i;
                    }
                }
            }
            else
            {
                if (
    document.meinForm.id.checkedselection 1;
            }
                    
            if (!
    selection == 1
            {
                
    alert("Es muss mindestens ein Eintrag ausgewählt sein.");
                return;
            }        
        }
        
    this.location.href= ('datei_' action'.php?action='action +'&id='document.meinForm.id[selectedIDX].value);
    }
    </
    script

    Comment


    • #3
      Hallo reallife,


      Jepp so klappt es und es wird die value übermittelt von id. Nur dabei bei der Wiedergabe this.location.href gibt das ? nicht aus.

      Dabei habe ich es anders gelöst, und falls jemand so etwas sucht hier:

      formular:
      Code:
      <script language="javascript">
      function doit(action,req) {
      	if (!document.doform) return;
      	if (document.doform.elements[0].name!='todo') return;
      	if (req != 1) {
      		var selection = 0;
      		if (document.doform.id.length) {
      			for (i = 0; i < document.doform.id.length; i++) {
      				if (document.doform.id[i].checked) selection = 1;
      			}
      		}else{
      		        if (document.doform.id.checked) selection = 1;
      		}				
      		if (!selection == 1) {
      			alert("Es muss mindestens ein Eintrag ausgewählt sein.");
      			return;
      		}		
      	}
      	document.doform.todo.value=action;
      	document.doform.submit();
      }
      </script>
      </head>
      <body>
      <form name="doform" method="post" action="datei_action.php">
      <input type="hidden" name="todo"> 
        <input type="radio" name="id" value="1"><br>
        <input type="radio" name="id" value="2"><br>
        <input type="radio" name="id" value="3"><br>
        <input type="radio" name="id" value="4"><br>
        <input type="radio" name="id" value="5"><br>
        <br>
        <a href="java script:doit('delete')">löschen</a> 
      <a href="java script:doit('rename')">umbenennen</a> 
      <a href="java script:doit('edit')">editieren</a> 
      <a href="java script:doit('copy')">kopieren</a> 
      <a href="java script:doit('move')">verschieben</a> 
      
      </form>



      datei_action.php:
      PHP Code:
      <?php
      if($_POST[id]== ""){
         
      Header("Location: datei_$_POST[todo].php");
         exit;
      } else {
         
      Header("Location: datei_$_POST[todo].php?action=edit&id=$_POST[id]");
         exit;
      }
      ?>



      Gruss

      Björn

      Comment


      • #4
        Hallo,

        Soweit klappt es mit dem Script. Doch eines würde ich dort noch einbauen, und zwar die erkennung wenn mehrere Checkboxen ausgewählt sind eine alert-Meldung kommt: es darf nur ein Eintrag ausgewählt werden.

        Hat irgendjemand eine Idee wie man das im vorhandenen Script verwirklichen kann?


        Gruss


        Björn

        Comment

        Working...
        X