tags:

views:

77

answers:

1

The idea is I am designing a monitoring system for for several geographic locations. It is annoying that user problems, accounts are seperate from network problems etc etc. Engineers are dealing with just networks but have little insight to the locations. So I want to make a visual understanding of this... I had trouble getting an easy way to manipulate a floor plan or campus map to validate with data. Voila!

Can't say I was impressed with the help from stackoverflow... I restated my question several times but kept at it and eventually found my own way...Hope this helps someone, please comment if any improvements. Next thing will be to bring in the post of the form prior so if lets say we have a 7 floor building ranging rooms from 100 to 150; 200 to 250 etc. that array will autoform the boxs so I just need to manipulate size and dimension. Customization would be nice. Updating the 'tag' afterwards. But I want to move on :)

    function addFormField(post) {
            var x=0;
            while(x<post){

            var id = document.getElementById("id").value;
        //  $("#divTxt").append("<p id='row" + id + "'><label for='txt" + id + "'>Field " + id + "&nbsp;&nbsp;<input type='text' size='20' name='txt[]' id='txt" + id + "'>&nbsp;&nbsp<a href='#' onClick='removeFormField(\"#row" + id
    + "\"); return false;'>Remove</a><p>");
            $("#divTxt").append("<p class='box' id='row" + id + "'>" + id
    + "<p>");       
            $('#row' + id).highlightFade({
                speed:500
            });

              $("#map").droppable({
              drop: function() { 
                ///

        //        $("#final :span").each(

            $("#final").append("<br/><span style='padding-left:10px'><input name='final"+id+"' id='final"+id +"' type='text' size='19'></span><span style='padding-left:22px'>"+    $("#x-coordinate").text()+"</span><span style='padding-left:15px'>"+    $("#y-coordinate").text()+"</span><span style='padding-left:15px'>"+ width
    +"</span><span style='padding-left:35px'>" + height+"</span>");


                /////
                }
            });

             $("#row"+ id).resizable(

             );
             $("#row"+ id).draggable({ 

        drag:function(){
             width = $(this).width();
             height = $(this).height();


             },
             containment: '#map', scroll: false 

             });

            id ++;
            document.getElementById("id").value = id;
            x++;

}
}

function removeFormField(id) {
    $(id).remove();
}

</script>

<body id="body">
<div id="contain" style="width: 802px; height:769px; border:2px solid #ccc; margin-left:100px"> 
 <img src="tip/ITHNY-campus.JPG" width="790px" height="760px" border="0" id="map">
</div>


<a href="#" onClick="addFormField(1); return false;">Add</a>
<form action="#" method="get" id="form1">
<input type="hidden" id="id" value="1">
<div id="divTxt"></div>
<p><input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="reset"></p>
</form>
<br/>
<table><tr>
<td>X:</td><td><pre id="x-coordinate" style="display:block"></pre></td></tr>
<tr><td>Y:</td><td><pre id="y-coordinate"></pre></td></tr></table>
<br/>
<div  id="final">
<table border="1">
<tr>
<th width="144">Name</th>
<th width="36">X</th>
<th width="36">Y</td>
<th width="36">W</th>
<th width="70">H</th>
</tr>
</table>

</div>
A: 

I don't know if this will help with your problem, but in any case: jQuery is selector-based, so use classes instead of IDs (remove the #s everywhere and change the corresponding id/name attributes to class attributes) and your code will be much more generic, hence more reusable and maintainable.

reinierpost
Thankyou for the note, But I found your comment very broad. My main concern with Jquery was id's that are dynamic. I also heard several things about avoiding classes vs the ladder. Quite the little argument.
Peter G Mac.